ldc-legaulois/app/Models/Claim.php
2025-06-10 13:30:22 +02:00

71 lines
1.7 KiB
PHP

<?php
namespace App\Models;
use App\Traits\Models\ActivityLog;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\SchemaOrg\Schema;
use Uwil\SchemaOrg\Laravel\Interfaces\SchemaOrgInterface;
use Uwil\SchemaOrg\Laravel\Traits\SchemaOrgTrait;
/**
* @property string $label Claim label.
* @property boolean $published Claim publish status.
* @property-read \Carbon\Carbon $created_at Created date.
* @property-read \Carbon\Carbon $updated_at Updated date.
*
* @property-read \App\Models\Product $products Product polymorphic relationship.
*/
class Claim extends Model implements SchemaOrgInterface
{
use ActivityLog;
use HasFactory;
use SchemaOrgTrait;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'label',
'published',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'published' => 'boolean',
];
// * METHODS
/**
* Create a SchemaOrg.
*
* @return \Spatie\SchemaOrg\DefinedTermSet
*/
public function toSchemaOrg(): \Spatie\SchemaOrg\DefinedTermSet
{
return Schema::definedTermSet()
->hasDefinedTerm(
Schema::definedTerm()->name($this->label)
);
}
// * RELATIONSHIPS
/**
* Get all of the products for the product type.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
*/
public function products(): \Illuminate\Database\Eloquent\Relations\MorphToMany
{
return $this->morphToMany(Product::class, 'productable');
}
}