56 lines
1.6 KiB
PHP
56 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models\FormBuilder;
|
|
|
|
use App\Enums\FormBuilder\FormFieldValidationRuleType;
|
|
use App\Models\Scopes\FormFieldValidationRuleScope;
|
|
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
|
|
/**
|
|
* Relational home for what was `form_fields.validation_rules` and
|
|
* `form_field_library.validation_rules` JSON. Polymorphic owner — morph
|
|
* aliases `form_field` and `form_field_library`. See ARCH-FORM-BUILDER
|
|
* §17.4 and ARCH-CONSOLIDATION-ADDENDUM-2026-04-24 §Q3.
|
|
*
|
|
* One row per (owner, rule_type). `parameters` JSON holds the rule-type-
|
|
* specific configuration (e.g. `{ "value": 3 }` for `min_length`, or
|
|
* `{ "mime_types": [...] }` for `allowed_mime_types`). Parameter shape
|
|
* validation lives in `FormFieldValidationRuleService`, not on the model.
|
|
*/
|
|
final class FormFieldValidationRule extends Model
|
|
{
|
|
use HasFactory;
|
|
use HasUlids;
|
|
|
|
protected $table = 'form_field_validation_rules';
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::addGlobalScope(new FormFieldValidationRuleScope());
|
|
}
|
|
|
|
protected $fillable = [
|
|
'owner_type',
|
|
'owner_id',
|
|
'rule_type',
|
|
'parameters',
|
|
'error_message_key',
|
|
];
|
|
|
|
/** @var array<string, string> */
|
|
protected $casts = [
|
|
'rule_type' => FormFieldValidationRuleType::class,
|
|
'parameters' => 'array',
|
|
];
|
|
|
|
public function owner(): MorphTo
|
|
{
|
|
return $this->morphTo('owner', 'owner_type', 'owner_id');
|
|
}
|
|
}
|