<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
class ProductRevision extends Model
{
use HasFactory, SoftDeletes;
protected $fillable = [
'revision_number',
'needs_documents',
'product_id',
];
protected $searchableFields = ['*'];
protected $table = 'product_revisions';
protected $casts = [
'needs_documents' => 'boolean',
];
/**
* Get the product of the product revision
*
* @return BelongsTo
*/
public function product(): BelongsTo
{
return $this->belongsTo(Product::class);
}
/**
* Get the order lines of the product revision
*
* @return HasMany
*/
public function orderLines(): HasMany
{
return $this->hasMany(OrderLine::class);
}
/**
* Get the product prices of the product revision
*
* @return HasMany
*/
public function productPrices(): HasMany
{
return $this->hasMany(ProductPrice::class);
}
public function getLabelAttribute()
{
return "{$this->product->code} - {$this->product->name}";
}
public function getTypeLabelAttribute()
{
return "Product";
}
}