78 lines
1.8 KiB
PHP
78 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\RegistrationFieldType;
|
|
use App\Models\Scopes\OrganisationScope;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
final class RegistrationFieldTemplate extends Model
|
|
{
|
|
use HasFactory;
|
|
use HasUlids;
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::addGlobalScope(new OrganisationScope());
|
|
}
|
|
|
|
protected $fillable = [
|
|
'organisation_id',
|
|
'label',
|
|
'slug',
|
|
'field_type',
|
|
'options',
|
|
'tag_category',
|
|
'is_required',
|
|
'is_filterable',
|
|
'is_portal_visible',
|
|
'is_admin_only',
|
|
'section',
|
|
'help_text',
|
|
'sort_order',
|
|
'is_system',
|
|
'is_active',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'field_type' => RegistrationFieldType::class,
|
|
'options' => 'array',
|
|
'is_required' => 'boolean',
|
|
'is_filterable' => 'boolean',
|
|
'is_portal_visible' => 'boolean',
|
|
'is_admin_only' => 'boolean',
|
|
'sort_order' => 'integer',
|
|
'is_system' => 'boolean',
|
|
'is_active' => 'boolean',
|
|
];
|
|
}
|
|
|
|
public function organisation(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Organisation::class);
|
|
}
|
|
|
|
public function scopeActive(Builder $query): Builder
|
|
{
|
|
return $query->where('is_active', true);
|
|
}
|
|
|
|
public function scopeSystem(Builder $query): Builder
|
|
{
|
|
return $query->where('is_system', true);
|
|
}
|
|
|
|
public function scopeOrdered(Builder $query): Builder
|
|
{
|
|
return $query->orderBy('sort_order');
|
|
}
|
|
}
|