wip
This commit is contained in:
parent
a3d2e6f0e6
commit
2d6cc23da8
|
|
@ -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');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
/**
|
||||
* 创建购物车商品记录
|
||||
* \Beike\Models\Cart::factory(300)->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)
|
||||
];
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue