$products * @property-read int|null $products_count * @property-read User|null $user * * @method static Builder|Cart active() * @method static Builder|Cart newModelQuery() * @method static Builder|Cart newQuery() * @method static Builder|Cart query() * @method static Builder|Cart whereCreatedAt($value) * @method static Builder|Cart whereId($value) * @method static Builder|Cart whereStatus($value) * @method static Builder|Cart whereUpdatedAt($value) * @method static Builder|Cart whereUserId($value) * @method static Builder|Cart withProducts() * * @mixin \Eloquent */ class Cart extends Model { protected $fillable = ['user_id', 'status']; protected function casts() { return [ 'status' => CartStatus::class, ]; } public function products() { return $this->belongsToMany(Product::class) ->withPivot('price', 'quantity') ->withTimestamps(); } public function user() { return $this->belongsTo(User::class); } #[Scope] protected function active(Builder $query) { return $query->where('status', CartStatus::Active); } #[Scope] protected function withProducts(Builder $query) { return $query->with(['products' => function ($product) { $product->withPivot('quantity', 'price'); }]); } }