In my Laravel application, I would like to check wether the value of the field uuid is present in table courses or in table contingents using validation rules. The UUID must be present in one of the two tables to proceed. Laravel requires the UUID to be present in both tables, when I'm applying the following ruleset:
$request->validate([
'uuid' => 'exists:courses,course_id',
'uuid' => 'exists:contingents,contingent_id
]);
Some kind of “differentiation logic” is required. It would be possible to achieve it with some if statements, but that wouldn't be a very clean way to solve the problem, I guess.
How can I tell Laravel that the UUID only needs to exist in ONE table for validation to be ok?
Thanks in advance.
['uuid' => '...', 'uuid' => '...'], the 2ndexistslogic will be the only one checked, since Array keys need to be unique, and if they're not, the "last" one takes precedence. The documentation is pretty good for Custom Rules though: laravel.com/docs/11.x/validation#custom-validation-rules