*/ protected $casts = [ 'translations' => 'array', 'default_is_required' => 'bool', 'default_is_filterable' => 'bool', 'is_system' => 'bool', 'is_active' => 'bool', 'usage_count' => 'int', ]; public function organisation(): BelongsTo { return $this->belongsTo(Organisation::class); } public function fields(): HasMany { return $this->hasMany(FormField::class, 'library_field_id'); } public function bindings(): MorphMany { return $this->morphMany(FormFieldBinding::class, 'owner'); } public function validationRules(): MorphMany { return $this->morphMany(FormFieldValidationRule::class, 'owner'); } public function configs(): MorphMany { return $this->morphMany(FormFieldConfig::class, 'owner'); } public function options(): MorphMany { return $this->morphMany(FormFieldOption::class, 'owner') ->orderBy('sort_order'); } /** * Force `$library->options` (no parens) to resolve to the morphMany * relation rather than the legacy JSON column attribute that lives * on the table until WS-5d commit 5 drops it. Removed at commit 5 * along with the column. * * @return \Illuminate\Database\Eloquent\Collection */ public function getOptionsAttribute(): \Illuminate\Database\Eloquent\Collection { if (! $this->relationLoaded('options')) { $this->load('options'); } /** @var \Illuminate\Database\Eloquent\Collection $relation */ $relation = $this->getRelation('options'); return $relation; } }