Add the count field to Item model.

main
KKlochko 2 years ago
parent 563254c725
commit ada0abd69d

@ -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);

@ -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');

Loading…
Cancel
Save