优化购物车商品表
parent
b4d8d98d8e
commit
e668ec9826
|
|
@ -32,7 +32,7 @@ class ShoppingCartItemController extends Controller
|
|||
{
|
||||
$input = $request->validate([
|
||||
'sku_id' => ['bail', 'required'],
|
||||
'qty' => ['bail', 'required', 'int', 'min:1'],
|
||||
'quantity' => ['bail', 'required', 'int', 'min:1'],
|
||||
]);
|
||||
|
||||
$sku = ProductSku::whereRelation('category', 'is_show', true)->online()->find($input['sku_id']);
|
||||
|
|
@ -44,11 +44,11 @@ class ShoppingCartItemController extends Controller
|
|||
$item = $request->user()->shoppingCartItems()->firstOrCreate([
|
||||
'sku_id' => $sku->id,
|
||||
], [
|
||||
'qty' => $input['qty'],
|
||||
'quantity' => $input['quantity'],
|
||||
]);
|
||||
|
||||
if (! $item->wasRecentlyCreated) {
|
||||
$item->increment('qty', $input['qty']);
|
||||
$item->increment('quantity', $input['quantity']);
|
||||
}
|
||||
|
||||
return response()->noContent();
|
||||
|
|
@ -64,7 +64,7 @@ class ShoppingCartItemController extends Controller
|
|||
public function update($id, Request $request)
|
||||
{
|
||||
$input = $request->validate([
|
||||
'qty' => ['bail', 'required', 'int', 'min:1'],
|
||||
'quantity' => ['bail', 'required', 'int', 'min:1'],
|
||||
]);
|
||||
|
||||
$item = $request->user()->shoppingCartItems()->findOrFail($id);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class ShoppingCartItemResource extends JsonResource
|
|||
return [
|
||||
'id' => $this->id,
|
||||
'sku' => ProductSkuSimpleResource::make($this->whenLoaded('sku')),
|
||||
'qty' => $this->qty,
|
||||
'quantity' => $this->quantity,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class ShoppingCartItem extends Model
|
|||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'qty' => 'int',
|
||||
'quantity' => 'int',
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
@ -19,7 +19,7 @@ class ShoppingCartItem extends Model
|
|||
protected $fillable = [
|
||||
'user_id',
|
||||
'sku_id',
|
||||
'qty',
|
||||
'quantity',
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class CreateShoppingCartItemsTable extends Migration
|
|||
$table->id();
|
||||
$table->unsignedBigInteger('user_id')->comment('用户ID');
|
||||
$table->unsignedBigInteger('sku_id')->comment('商品ID');
|
||||
$table->unsignedInteger('qty')->default(0)->comment('购买数量');
|
||||
$table->unsignedInteger('quantity')->default(0)->comment('购买数量');
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['user_id', 'sku_id']);
|
||||
|
|
|
|||
Loading…
Reference in New Issue