*/ protected $fillable = [ 'page_id', 'name', 'visibility', 'data', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'visibility' => 'boolean', 'data' => 'object', ]; /** * Perform any actions required after the model boots. * * @return void */ protected static function booted() { static::saving(function ($section) { $section->load('page'); if ( $section->page->type === StaticPageType::raiseSustainably && $section->name === 'section 3' && ! str_contains($section->data->title->value, ':nbrKeyList') ) { throw ValidationException::withMessages([ 'data.title.value' => __('validation.custom.data_title_value.contains_placeholder'), ]); } }); } /** * Returns the static page this section belongs to. */ public function page(): BelongsTo { return $this->belongsTo(StaticPage::class); } /** * Returns all blocks associated with this section. */ public function blocks(): HasMany { return $this->hasMany(Block::class, 'section_id'); } /** * Returns all pictos associated with this section, ordered by their position. */ public function pictos(): HasMany { return $this->hasMany(Picto::class, 'section_id')->orderBy('order'); } }