status === 'active') { $exists = self::where('product_id', $contract->product_id) ->where('category', $contract->category) ->where('status', 'active') ->when($contract->exists, fn ($q) => $q->where('id', '!=', $contract->id)) ->exists(); if ($exists) { throw new \RuntimeException( __('feedback.contract_duplicate_body', [ 'product' => $contract->product?->name ?? $contract->product_id, 'customer' => $contract->customer?->name ?? '?', ]) ); } } }); } protected function casts(): array { return [ 'start_date' => 'date', 'end_date' => 'date', 'printed_at' => 'date', ]; } public function product(): BelongsTo { return $this->belongsTo(Product::class); } public function customer(): BelongsTo { return $this->belongsTo(Customer::class); } public function feedbacks(): HasMany { return $this->hasMany(Feedback::class); } }