date)->format('d.m.Y'); } public function getPriceAttribute($price) { return Money::CHF($price); } public function getDeletedAtAttribute($deleted_at) { if ($deleted_at) { return Carbon::parse($deleted_at)->format('d.m.Y'); } return null; } public function isBuyContract() { return $this->type === (string)ContractType::BuyContract; } public function isSellContract() { return $this->type === (string)ContractType::SellContract; } public function documents() { return $this->morphMany(Document::class, 'documentable'); } public function contact() { return $this->belongsTo(Contact::class)->withTrashed(); } public function car() { return $this->belongsTo(Car::class)->withTrashed(); } public function scopeThisYear($query) { $query->where('date', '>', date('Y')); } public function scopeSoldThisYear($query) { $query->buyContracts()->thisYear(); } public function scopeBoughtThisYear($query) { $query->sellContracts()->thisYear(); } public function scopeBuyContracts($query) { $query->where('type', (string)ContractType::BuyContract); } public function scopeSellContracts($query) { $query->where('type', (string)ContractType::SellContract); } }