belongsTo(User::class); } public function cart(): BelongsTo { return $this->belongsTo(Cart::class); } /** * Stripe session id helps to update status later from webhook * * @return HasOne */ public function stripeSession(): HasOne { return $this->hasOne(StripeSession::class); } /** * @return HasMany */ public function payments(): HasMany { return $this->hasMany(Payment::class); } protected function totalAmount(): Attribute { return Attribute::make( fn () => $this->cart?->products->sum(fn ($product) => $product->pivot->price * $product->pivot->quantity) ?? 0 ); } }