103 lines
2.5 KiB
PHP
103 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\BreedingBlocType;
|
|
use App\Enums\BreedingPageType;
|
|
use App\Enums\InputType;
|
|
use App\Traits\MiniAcfModel;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Str;
|
|
use Kwaadpepper\Enum\Traits\CastsEnums;
|
|
|
|
class BreedingPage extends Model
|
|
{
|
|
use CastsEnums;
|
|
use HasFactory;
|
|
use MiniAcfModel;
|
|
|
|
/**
|
|
* The attributes that should be cast to native types.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $casts = [
|
|
'content' => 'array',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be cast to Enums.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $enumCasts = [
|
|
'type' => BreedingPageType::class,
|
|
'media_type' => InputType::class
|
|
];
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'title', 'headerContent',
|
|
'seo_title', 'seo_description',
|
|
'headerContent', 'subtitle',
|
|
'subtitleContent', 'media_type',
|
|
'picture', 'picture_alt', 'picture_title',
|
|
'video', 'content', 'status'
|
|
];
|
|
|
|
/**
|
|
* Perform any actions required after the model boots.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected static function booted()
|
|
{
|
|
static::creating(function (self $model) {
|
|
$model->slug = Str::slug($model->title);
|
|
OldSlugable::removeSameSlugs($model, $model->slug);
|
|
});
|
|
static::updating(function (self $model) {
|
|
$model->slug = Str::slug($model->title);
|
|
if ($model->slug != $model->getOriginal('slug')) {
|
|
OldSlugable::removeSameSlugs($model, $model->getOriginal('slug'));
|
|
}
|
|
OldSlugable::insertSlug($model);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Get the route key for the model.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getRouteKeyName()
|
|
{
|
|
return 'slug';
|
|
}
|
|
|
|
/**
|
|
* Get Blocks Template Data
|
|
*
|
|
* @return array
|
|
*/
|
|
public static function getBlocks(): array
|
|
{
|
|
return [
|
|
BreedingBlocType::bloc1()->value => [
|
|
'type' => BreedingBlocType::bloc1(),
|
|
'content' => [
|
|
'dropdownArray' => [
|
|
'label' => 'Dropdowns',
|
|
'inputType' => InputType::dropdownArray(),
|
|
'value' => []
|
|
]
|
|
]
|
|
]
|
|
];
|
|
}
|
|
}
|