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.
2
Answers
you can use custom validation rule
first of all make new rule using
php artisan make:rule ruleName.
now write this function in the rule class
after that use it in your controller like that