year)) { $attributes->year = year(); } }); } protected $appends = [ 'product_price', 'installation_price', 'total_price', 'product_price_txt', 'installation_price_txt', 'total_price_txt', 'image' ]; protected function productPrice(): Attribute { return Attribute::make( get: fn(int $value) => (float) $value / 100, set: fn (float $value) => (int) ($value * 100), ); } protected function installationPrice(): Attribute { return Attribute::make( get: fn(int $value) => (float) $value / 100, set: fn (float $value) => (int) ($value * 100), ); } protected function totalPrice(): Attribute { return Attribute::make( get: fn(int $value) => (float) $value / 100, set: fn (float $value) => (int) ($value * 100), ); } public function productPriceTxt(): Attribute { return Attribute::make( get: fn($value) => Price::format($this->product_price), ); } public function installationPriceTxt(): Attribute { return Attribute::make( get: fn($value) => Price::format($this->installation_price), ); } protected function totalPriceTxt(): Attribute { return Attribute::make( get: fn($value) => Price::format($this->total_price), ); } public function commonName(): Attribute { return Attribute::make( get: fn($value) => $this->article . ', №' . $this->nomenclature_number, ); } /** * @return BelongsToMany */ public function orders(): BelongsToMany { return $this->belongsToMany(Order::class, 'products_sku', 'order_id', 'product_id'); } public function certificate(): BelongsTo { return $this->belongsTo(File::class, 'certificate_id', 'id'); } public function maf_orders(): HasMany { return $this->hasMany(MafOrder::class, 'product_id', 'id'); } public function hasRelations(): bool { if($this->maf_orders && ($this->maf_orders->count() > 0)) { return true; } if($this->orders && ($this->orders->count() > 0)) { return true; } return false; } public function image(): Attribute { if(file_exists(public_path() . '/images/main/' . $this->article . '.0000.0000.jpg')) { $path = url('/images/main/' . $this->article . '.0000.0000.jpg'); } else { $path = ''; } return Attribute::make( get: fn() => $path, ); } }