| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace App\Models;
- use App\Helpers\Price;
- use Illuminate\Database\Eloquent\Casts\Attribute;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\SoftDeletes;
- class Product extends Model
- {
- use SoftDeletes;
- const DEFAULT_SORT_BY = 'article';
- protected $fillable = [
- 'year',
- 'name_tz',
- 'type_tz',
- 'nomenclature_number',
- 'sizes',
- 'manufacturer',
- 'unit',
- 'type',
- 'price_status',
- 'product_price',
- 'installation_price',
- 'service_price',
- 'total_price',
- 'manufacturer_name',
- 'article',
- 'note',
- ];
- protected $appends = ['product_price', 'installation_price', 'service_price', 'total_price',
- 'product_price_txt', 'installation_price_txt', 'service_price_txt', 'total_price_txt',];
- 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 servicePrice(): 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 servicePriceTxt(): Attribute
- {
- return Attribute::make(
- get: fn($value) => Price::format($this->service_price),
- );
- }
- protected function totalPriceTxt(): Attribute
- {
- return Attribute::make(
- get: fn($value) => Price::format($this->total_price),
- );
- }
- }
|