Accessing the current model inside custom validation rule

Hi. Is there a way to access the current model value inside the custom validation function?
Forms\Components\Radio::make('status')
->options([
'draft' => 'Draft',
'public' => 'Public'
])
->descriptions([
'draft' => 'Will not be visible to students',
'public' => 'Will be visible to students'
])
->hiddenOn('create')
->default('draft')
->rules([
function () {
return function (string $attribute, $value, Closure $fail) {
// Here
};
}
])
->required(),
Forms\Components\Radio::make('status')
->options([
'draft' => 'Draft',
'public' => 'Public'
])
->descriptions([
'draft' => 'Will not be visible to students',
'public' => 'Will be visible to students'
])
->hiddenOn('create')
->default('draft')
->rules([
function () {
return function (string $attribute, $value, Closure $fail) {
// Here
};
}
])
->required(),
I want to check if the model has children or not.
1 Reply
Bezhan
Bezhan2y ago
->rules([function(string $context, ?Model $record) {
return function (string $attribute, $value, Closure $fail) use($record){
// now you can do anything with the record
};
}])
->rules([function(string $context, ?Model $record) {
return function (string $attribute, $value, Closure $fail) use($record){
// now you can do anything with the record
};
}])
you could check the context as will if it edit or view just to make sure there is not side-effect....
Want results from more Discord servers?
Add your server