Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Add ExcludeIf and ProhibitedIf Validation Methods #41617

Merged
merged 2 commits into from
Mar 25, 2022
Merged

[9.x] Add ExcludeIf and ProhibitedIf Validation Methods #41617

merged 2 commits into from
Mar 25, 2022

Conversation

intrepidws
Copy link
Contributor

Much like the existing Rule::requiredIf() method allows for more complex conditions, I am proposing the addition of Rule::excludeIf() and Rule::prohibitedIf()methods. These work in much the same way and will allow for more complex conditions. Examples below.

use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
 
Validator::make($request->all(), [
    'role_id' => Rule::prohibitedIf($request->user()->is_expired),
]);
 
Validator::make($request->all(), [
    'role_id' => Rule::prohibitedIf(fn () => $request->user()->is_expired),
]);

Validator::make($request->all(), [
    'role_id' => Rule::excludeIf($request->user()->is_expired),
]);
 
Validator::make($request->all(), [
    'role_id' => Rule::excludeIf(fn () => $request->user()->is_expired),
]);

@taylorotwell taylorotwell merged commit d89400b into laravel:9.x Mar 25, 2022
@intrepidws intrepidws deleted the addl-validation-if-methods branch March 29, 2022 02:21
@GrahamCampbell GrahamCampbell changed the title Add ExcludeIf and ProhibitedIf Validation Methods [9.x] Add ExcludeIf and ProhibitedIf Validation Methods Apr 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants