| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- namespace App\Models;
- use App\Helpers\Price;
- use Illuminate\Database\Eloquent\Casts\Attribute;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- class ContractorInstallationPrice extends Model
- {
- use HasFactory;
- protected $fillable = [
- 'contractor_id',
- 'product_id',
- 'catalog_year',
- 'name_in_spec',
- 'price',
- ];
- protected $appends = [
- 'price_txt',
- ];
- public function contractor(): BelongsTo
- {
- return $this->belongsTo(Contractor::class);
- }
- public function product(): BelongsTo
- {
- return $this->belongsTo(Product::class, 'product_id')->withoutGlobalScope(\App\Models\Scopes\YearScope::class)->withTrashed();
- }
- protected function price(): Attribute
- {
- return Attribute::make(
- get: fn(int|null $value) => (float) ($value ?? 0) / 100,
- set: fn(float|int|string|null $value) => (int) round(((float) ($value ?? 0)) * 100),
- );
- }
- protected function priceTxt(): Attribute
- {
- return Attribute::make(
- get: fn() => Price::format($this->price),
- );
- }
- }
|