*/ protected $fillable = [ 'title', 'text', 'link_url', 'link_title', 'link_target', 'link_status', 'picture', 'picture_alt', 'picture_title', 'picture_status', 'background_picture', 'background_picture_alt', 'background_picture_title', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'type' => MenuNodeType::class, 'link_target' => 'bool', 'link_status' => 'bool', 'picture_status' => 'bool', ]; /** * Perform any actions required after the model boots. * * @return void * @throws \ErrorException Not allowed to create an instance of this. */ protected static function booted(): void { static::creating(fn () => throw new \ErrorException('Not allowed to create an instance of this')); static::updating(fn (self $model) => self::denyHandlingSomeTypes($model)); static::deleting(fn () => throw new \ErrorException('Not allowed to create an instance of this')); } // * METHODS /** * Deny Handling some of the MenuNodeData * * @param self $model * @return void * @throws \RuntimeException Database operations are not allowed for some types. */ private static function denyHandlingSomeTypes(self $model): void { if (in_array($model->type, [MenuNodeType::siteLogo, MenuNodeType::link])) { throw new \RuntimeException('Database operations are not allowed the type ' . $model->type->label()); } } }