28 lines
635 B
PHP
28 lines
635 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Database\Factories\CartFactory;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
|
|
class Cart extends Model
|
|
{
|
|
/** @use HasFactory<CartFactory> */
|
|
use HasFactory;
|
|
|
|
protected $fillable = ['user_id'];
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function products(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Product::class)->withPivot('quantity');
|
|
}
|
|
}
|