aravel 8 now has three validation rules for prohibited fields, including prohibited_if
, prohibited_unless
, and prohibited
. Let’s walk through a few examples of where the prohibited*
validation rules might be useful, and look at each one in more detail.
Jess Archer contributed the prohibited if/unless validation rules released in Laravel Laravel 8.32. The basic idea of “prohibited” validation rules is that a given field should be prohibited from having data if another field is present or if a field should be allowed in a request at all.
Here’s the example Jess provided in the pull request for this feature, which illustrates perfectly how to use this rule to explicitly prevent contradictory input:
Validator::validate([
'is_deceased' => false,
'date_of_death' => '2021-03-09'
], [
'date_of_death' => 'prohibited_unless:is_deceased,true'
]);
#tutorials #laravel