From e668ec9826a2cadb45e578ef028f2f810b432971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Tue, 7 Dec 2021 17:01:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=B4=AD=E7=89=A9=E8=BD=A6?= =?UTF-8?q?=E5=95=86=E5=93=81=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Api/Http/Controllers/ShoppingCartItemController.php | 8 ++++---- .../Api/Http/Resources/ShoppingCartItemResource.php | 2 +- app/Models/ShoppingCartItem.php | 4 ++-- ...2021_12_06_171251_create_shopping_cart_items_table.php | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/Endpoint/Api/Http/Controllers/ShoppingCartItemController.php b/app/Endpoint/Api/Http/Controllers/ShoppingCartItemController.php index 5b49f7c2..c2cdc90c 100644 --- a/app/Endpoint/Api/Http/Controllers/ShoppingCartItemController.php +++ b/app/Endpoint/Api/Http/Controllers/ShoppingCartItemController.php @@ -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); diff --git a/app/Endpoint/Api/Http/Resources/ShoppingCartItemResource.php b/app/Endpoint/Api/Http/Resources/ShoppingCartItemResource.php index c4205e34..0cb31037 100644 --- a/app/Endpoint/Api/Http/Resources/ShoppingCartItemResource.php +++ b/app/Endpoint/Api/Http/Resources/ShoppingCartItemResource.php @@ -18,7 +18,7 @@ class ShoppingCartItemResource extends JsonResource return [ 'id' => $this->id, 'sku' => ProductSkuSimpleResource::make($this->whenLoaded('sku')), - 'qty' => $this->qty, + 'quantity' => $this->quantity, ]; } } diff --git a/app/Models/ShoppingCartItem.php b/app/Models/ShoppingCartItem.php index db000405..afe0739c 100644 --- a/app/Models/ShoppingCartItem.php +++ b/app/Models/ShoppingCartItem.php @@ -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', ]; /** diff --git a/database/migrations/2021_12_06_171251_create_shopping_cart_items_table.php b/database/migrations/2021_12_06_171251_create_shopping_cart_items_table.php index 7580195b..12bd3108 100644 --- a/database/migrations/2021_12_06_171251_create_shopping_cart_items_table.php +++ b/database/migrations/2021_12_06_171251_create_shopping_cart_items_table.php @@ -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']);