diff --git a/beike/Models/Cart.php b/beike/Models/Cart.php index b937f060..054d955b 100644 --- a/beike/Models/Cart.php +++ b/beike/Models/Cart.php @@ -2,8 +2,9 @@ namespace Beike\Models; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Factories\HasFactory; class Cart extends Model { @@ -11,7 +12,7 @@ class Cart extends Model protected $fillable = ['customer_id', 'selected', 'product_id', 'product_sku_id', 'quantity']; - public function sku() + public function sku(): BelongsTo { return $this->belongsTo(ProductSku::class, 'product_sku_id', 'id'); } diff --git a/database/factories/Beike/Models/CartFactory.php b/database/factories/Beike/Models/CartFactory.php new file mode 100644 index 00000000..cb075829 --- /dev/null +++ b/database/factories/Beike/Models/CartFactory.php @@ -0,0 +1,31 @@ +create(['customer_id'=>2]) + */ + +namespace Database\Factories\Beike\Models; + +use Beike\Models\Cart; +use Illuminate\Database\Eloquent\Factories\Factory; + +class CartFactory extends Factory +{ + protected $model = Cart::class; + + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'customer_id' => 0, + 'selected' => 1, + 'product_id' => rand(1, 1000), + 'product_sku_id' => rand(1, 1000), + 'quantity' => rand(1, 10) + ]; + } +}