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
You can inject $get from the outer closure
@ZedoX thank you it worked perfectly