diff --git a/app/Models/Item.php b/app/Models/Item.php index 4ef4d5d..f4e5bee 100644 --- a/app/Models/Item.php +++ b/app/Models/Item.php @@ -19,8 +19,21 @@ class Item extends Model 'price', 'image', 'category_id', + // if an item in a cart, then the count is a nonzero value. + 'count', ]; + public function getCount() + { + return $this->count; + } + + public function setCount($count = 1) + { + $this->count = $count; + $this->save(); + } + public function category(): BelongsTo { return $this->belongsTo(Category::class); diff --git a/database/migrations/2023_06_14_140000_create_items_table.php b/database/migrations/2023_06_14_140000_create_items_table.php index 22bbe87..e732e64 100644 --- a/database/migrations/2023_06_14_140000_create_items_table.php +++ b/database/migrations/2023_06_14_140000_create_items_table.php @@ -20,6 +20,7 @@ return new class extends Migration $table->string('description'); $table->decimal('price', 8, 2); $table->string('image')->nullable(); + $table->bigInteger('count')->default(0); $table->foreign('category_id')->references('id') ->on('categories')->onDelete('cascade');