ldc-legaulois/app/Models/Claim.php

69 lines
1.6 KiB
PHP
Raw Permalink Normal View History

2024-06-10 16:47:07 +02:00
<?php
namespace App\Models;
use App\Traits\Models\ActivityLog;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
2026-09-25 16:25:31 +02:00
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;
2024-06-10 16:47:07 +02:00
/**
2026-09-25 16:25:31 +02:00
* @property string $label Claim label.
* @property bool $published Claim publish status.
2024-06-10 16:47:07 +02:00
* @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
2024-06-10 16:47:07 +02:00
{
use ActivityLog;
use HasFactory;
use SchemaOrgTrait;
2024-06-10 16:47:07 +02:00
/**
* 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.
*/
2026-09-25 16:25:31 +02:00
public function toSchemaOrg(): DefinedTermSet
{
return Schema::definedTermSet()
->hasDefinedTerm(
Schema::definedTerm()->name($this->label)
);
}
2024-06-10 16:47:07 +02:00
// * RELATIONSHIPS
/**
* Get all of the products for the product type.
*/
2026-09-25 16:25:31 +02:00
public function products(): MorphToMany
2024-06-10 16:47:07 +02:00
{
return $this->morphToMany(Product::class, 'productable');
}
}