topnotch_website/app/Models/ProductService.php

69 lines
1.6 KiB
PHP
Raw Permalink Normal View History

2024-09-09 15:29:31 -07:00
<?php
namespace App\Models;
2025-01-19 12:51:37 -05:00
use App\Observers\ProductServiceObserver;
2024-09-18 16:00:06 -07:00
use Database\Factories\ProductServiceFactory;
2025-01-19 12:51:37 -05:00
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
2024-09-09 15:29:31 -07:00
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
2025-01-19 12:51:37 -05:00
#[ObservedBy(ProductServiceObserver::class)]
2024-09-09 15:29:31 -07:00
class ProductService extends Model
{
2024-09-18 16:00:06 -07:00
/** @use HasFactory<ProductServiceFactory> */
2024-09-09 15:29:31 -07:00
use HasFactory, SoftDeletes;
protected $fillable = [
'order_id',
2024-09-19 11:52:04 -07:00
'service_file_id',
'service_type_id',
2024-09-09 15:29:31 -07:00
'placement',
2024-10-25 11:30:20 -04:00
'setup_amount',
2024-09-09 15:29:31 -07:00
'amount',
'amount_price',
2024-09-20 12:12:45 -07:00
'notes',
2024-09-09 15:29:31 -07:00
];
protected $appends = [
'service_details',
'price',
];
protected $touches = ['order'];
public function getPriceAttribute(): float
{
return number_format($this->amount * $this->amount_price, 2);
}
public function getServiceDetailsAttribute(): string
{
$file = $this->serviceFile;
2025-01-19 12:51:37 -05:00
if (! $file) {
return 'Error: could not find service file';
}
return $file->name.', '.$this->placement.', '.$file->width.' W, '.$file->height.' H';
}
2024-11-15 00:37:01 -05:00
public function serviceType(): BelongsTo
{
return $this->belongsTo(ServiceType::class);
}
2024-09-09 15:29:31 -07:00
public function order(): BelongsTo
{
return $this->belongsTo(Order::class);
}
2024-09-19 11:52:04 -07:00
public function serviceFile(): BelongsTo
2024-09-09 15:29:31 -07:00
{
2024-09-19 11:52:04 -07:00
return $this->BelongsTo(ServiceFile::class);
2024-09-09 15:29:31 -07:00
}
}