Oct 30, 2025
8
Level 6
Validations & Custom Rule
Is there a way to prevent the Custom Rule from running when the prior rules failed?
$userInput = [
'offset' => [
'a' => "abcd",
'b' => "abcd,
],
'photo' => $file
];
in FormRequest
//...
['photo' => ['image']],
['offset' => ['bail', 'array:x,y', new OffsetCheck($this->photo)]],
['offset.*' => ['numeric'],
OffsetCheck uses the values of x and y but got a and b so it should throw an error and stop before going to the custom rule but I still get Undefined array key "x" from OffsetCheck. Do I need to repeat the set of validations inside the custom rule?
Level 6
Yeah that's what array:keys throws when it is invalid.
I just combined those two
['offset' => ['bail', 'array:x,y', 'required_array_keys:x,y', new OffsetCheck]],
Please or to participate in this conversation.