'decimal:2', 'is_active' => 'boolean', ]; /** * Get the work associated with the price * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function work() { return $this->belongsTo(Work::class); } /** * Get the dealer associated with the price * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function dealer() { return $this->belongsTo(Dealer::class); } /** * Scope to get only active prices * * @param \Illuminate\Database\Eloquent\Builder $query * @return \Illuminate\Database\Eloquent\Builder */ public function scopeActive($query) { return $query->where('is_active', true); } /** * Get formatted price with currency * * @return string */ public function getFormattedPriceAttribute() { return number_format($this->price, 0, ',', '.') . ' ' . $this->currency; } /** * Get price for specific work and dealer * * @param int $workId * @param int $dealerId * @return WorkDealerPrice|null */ public static function getPriceForWorkAndDealer($workId, $dealerId) { return static::where('work_id', $workId) ->where('dealer_id', $dealerId) ->active() ->first(); } }