73 lines
1.8 KiB
PHP
73 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models\FormBuilder;
|
|
|
|
use App\Models\Organisation;
|
|
use App\Models\Scopes\OrganisationScope;
|
|
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
|
|
|
final class FormFieldLibrary extends Model
|
|
{
|
|
use HasFactory;
|
|
use HasUlids;
|
|
|
|
protected $table = 'form_field_library';
|
|
|
|
public string $organisationScopeColumn = 'organisation_id';
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::addGlobalScope(new OrganisationScope());
|
|
}
|
|
|
|
protected $fillable = [
|
|
'organisation_id',
|
|
'name',
|
|
'slug',
|
|
'field_type',
|
|
'label',
|
|
'help_text',
|
|
'options',
|
|
'validation_rules',
|
|
'default_is_required',
|
|
'default_is_filterable',
|
|
'translations',
|
|
'description',
|
|
'is_active',
|
|
];
|
|
|
|
/** @var array<string, string> */
|
|
protected $casts = [
|
|
'options' => 'array',
|
|
'validation_rules' => 'array',
|
|
'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');
|
|
}
|
|
}
|