Custom rules based on other form values

Am trying to validate a text value based on two parameters entered in the form and am facing hard time getting the other value into the rule to use it Could anyone help me find out how to do it Attached is my code Check TextInput::make('serial_number') ->label('Serial Number') ->placeholder('Serial Number') ->required() // ->unique('aircraft', 'serial_number') ->rules([ function () { return function (string $attribute, $value, Closure $fail) { dd($get('manufacturer_id')); $fail("The {$attribute} is invalid."); }; }, ]) ->numeric(),
2 Replies
ZedoX
ZedoX16mo ago
You can inject $get from the outer closure
->rules([
function ($get) {
return function (string $attribute, $value, Closure $fail) use ($get) {
$get('manufacture_id');
//..
}
}]);
->rules([
function ($get) {
return function (string $attribute, $value, Closure $fail) use ($get) {
$get('manufacture_id');
//..
}
}]);
abedrabaia
abedrabaiaOP16mo ago
@ZedoX thank you it worked perfectly
Want results from more Discord servers?
Add your server