*/ protected $fillable = [ 'seo_title', 'seo_description', 'title', 'content', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'type' => StaticPageType::class, ]; /** * Perform any actions required after the model boots. * * @return void */ protected static function booted(): void { static::creating(function () { throw new \RuntimeException("Creating a new page is not authorized"); }); static::updating(function (self $model) { // * ASSERTIONS self::assertTitleIsUnique($model->title, $model->id); // * CHANGES $model->slug = Str::slug($model->title); }); static::deleting(function () { throw new \RuntimeException('Deleting a page is not authorized'); }); } // * METHODS /** * Asserts using validation that the title is unique * * @param string|null $title * @param integer|null $id * @return void * @throws \Illuminate\Validation\ValidationException If an actu title already exists. */ private static function assertTitleIsUnique(string|null $title, ?int $id = null) { $table = (new self())->getTable(); ToolboxHelper::assertFieldIsUnique($table, 'title', $title, $id); ToolboxHelper::assertFieldIsUnique($table, 'slug', Str::slug($title), $id); } // * SEO TRAIT OVERLOAD /** * Transform to seoModel * * @return \Uwil\Seo\Laravel\Objects\SeoItem */ public function toSeoItem(): SeoItem { return new SeoItem( \trans('models.classes.' . Str::singular($this->getTable())), $this->seo_title, $this->seo_description, true, \route(\config('seo.bo_route_prefix') . $this->getTable() . '.edit', $this), '' ); } }