ldc-legaulois/app/Models/Claim.php
2026-09-25 16:25:31 +02:00

68 lines
1.6 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;
use Spatie\SchemaOrg\DefinedTermSet;
use Spatie\SchemaOrg\Schema;
use Uwil\SchemaOrg\Laravel\Interfaces\SchemaOrgInterface;
use Uwil\SchemaOrg\Laravel\Traits\SchemaOrgTrait;
/**
* @property string $label Claim label.
* @property bool $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.
*/
public function toSchemaOrg(): DefinedTermSet
{
return Schema::definedTermSet()
->hasDefinedTerm(
Schema::definedTerm()->name($this->label)
);
}
// * RELATIONSHIPS
/**
* Get all of the products for the product type.
*/
public function products(): MorphToMany
{
return $this->morphToMany(Product::class, 'productable');
}
}