Edit File: Product.php
<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; use Spatie\Translatable\HasTranslations; class Product extends BaseModel { use HasFactory, HasTranslations, SoftDeletes; public $translatable = ['name', 'description']; protected $fillable = [ 'name', 'description', 'category_id', 'provider_id', 'has_price', 'price', 'price_after_discount', ]; protected $casts = [ 'has_price' => 'boolean', ]; public function getHasPriceTextAttribute() { return trans('apis.has_price.' . (int) $this->has_price); } public function category(): BelongsTo { return $this->belongsTo(Category::class); } public function provider(): BelongsTo { return $this->belongsTo(Provider::class); } public function productImages(): HasMany { return $this->hasMany(ProductImage::class); } public function productClassifications(): HasMany { return $this->hasMany(ProductClassification::class); } public function orderItems() { return $this->hasMany(OrderItem::class); } public function negotationOrder() { return $this->hasMany(NegotiationOrder::class,'product_id','id'); } public function cartItems() { return $this->hasMany(CartItem::class); } public static function boot() { parent::boot(); static::deleted(function ($product) { $product->cartItems()->delete(); }); } }
Back to File Manager