*/ protected function casts(): array { return [ 'status' => CartStatus::class, ]; } public function products(): BelongsToMany { return $this->belongsToMany(Product::class) ->withPivot('price', 'quantity') ->withTimestamps(); } public function user(): BelongsTo { return $this->belongsTo(User::class); } public function order(): BelongsTo { return $this->belongsTo(Order::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'); }]); } }