'json', 'active_columns' => 'json', 'description' => 'json', ]; /** @var array */ public $dates = ['from', 'to', 'registration_from', 'registration_until']; /** * @return SluggableConfig */ public function sluggable(): array { return [ 'slug' => ['source' => ['name']], ]; } /** * @return HasMany */ public function participants(): HasMany { return $this->hasMany(Participant::class); } public function registerMediaCollections(): void { $this->addMediaCollection('headerImage') ->singleFile() ->maxWidth(fn () => 500) ->forceFileName(fn (Form $model, string $name) => $model->slug) ->registerMediaConversions(function (Media $media) { $this->addMediaConversion('square')->fit(Manipulations::FIT_CROP, 400, 400); }); } /** * @return array */ public function getRegistrationRules(): array { return $this->getFields()->reduce(function ($carry, $current) { $field = Field::fromConfig($current); return [ ...$carry, ...$field->getRegistrationRules(), ]; }, []); } /** * @return array */ public function getRegistrationMessages(): array { return $this->getFields()->reduce(function ($carry, $current) { $field = Field::fromConfig($current); return [ ...$carry, ...$field->getRegistrationMessages(), ]; }, []); } /** * @return array */ public function getRegistrationAttributes(): array { return $this->getFields()->reduce(function ($carry, $current) { $field = Field::fromConfig($current); return [ ...$carry, ...$field->getRegistrationAttributes(), ]; }, []); } /** * @return Collection */ public function getFields(): Collection { return collect($this->config['sections'])->reduce(fn ($carry, $current) => $carry->merge($current['fields']), collect([])); } // --------------------------------- Searching --------------------------------- // ***************************************************************************** /** * Get the indexable data array for the model. * * @return array */ public function toSearchableArray() { return [ 'from' => $this->from->timestamp, 'to' => $this->to->timestamp, 'name' => $this->name, ]; } public static function booted(): void { static::saving(function (self $model) { if (is_null($model->active_columns)) { $model->setAttribute('active_columns', $model->getFields()->take(4)->pluck('key')->toArray()); } }); } }