ldc-legaulois/app/Models/Product.php
2024-04-16 11:07:16 +02:00

94 lines
2.3 KiB
PHP

<?php
namespace App\Models;
use App\Traits\Models\ActivityLog;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
/**
* @property string $label Product label.
* @property-read \Carbon\Carbon $created_at Created date.
* @property-read \Carbon\Carbon $updated_at Updated date.
*/
class Product extends Model
{
use ActivityLog;
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'label',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [];
/**
* Perform any actions required after the model boots.
*
* @return void
*/
protected static function booted(): void
{
static::creating(function (self $productModel) {
});
static::updating(function (self $productModel) {
});
static::updated(function (self $productModel) {
});
static::deleted(function (self $productModel) {
});
}
// * RELATIONSHIPS
/**
* Get all of the ranges that are assigned this product.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
*/
public function ranges(): MorphToMany
{
return $this->morphedByMany(Range::class, 'productable');
}
/**
* Get all of the subranges that are assigned this product.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
*/
public function subranges(): MorphToMany
{
return $this->morphedByMany(Subrange::class, 'productable');
}
/**
* Get all of the meats that are assigned this product.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
*/
public function meats(): MorphToMany
{
return $this->morphedByMany(Meat::class, 'productable');
}
/**
* Get all of the submeats that are assigned this product.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
*/
public function submeats(): MorphToMany
{
return $this->morphedByMany(Submeat::class, 'productable');
}
}