Move common things into the model level validation

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2022-11-17 19:41:10 +00:00
parent 3997085faf
commit 24841a75d4

View file

@ -48,7 +48,11 @@ class CustomField extends Model
*
* @var array
*/
protected $rules = [];
protected $rules = [
'name' => 'required|unique:custom_fields',
'element' => 'required','in:text,listbox,textarea,checkbox,radio',
'field_encrypted' => 'nullable|boolean',
];
/**
* The attributes that are mass assignable.
@ -357,15 +361,9 @@ class CustomField extends Model
public function validationRules($regex_format = null)
{
return [
'name' => 'required|unique:custom_fields',
'element' => [
'required',
Rule::in(['text', 'listbox', 'textarea', 'checkbox', 'radio']),
],
'format' => [
Rule::in(array_merge(array_keys(self::PREDEFINED_FORMATS), self::PREDEFINED_FORMATS, [$regex_format])),
],
'field_encrypted' => 'nullable|boolean',
]
];
}