Laravel 8.x Conditional Validation Rule Support Example

Hello devs did you know that the team of laravel released conditional validation rule support in their 8.x version. You can see the  Pull Request #38361 for implementation details. I am here to show you what is conditional validation rule support in Laravel?

To understand the conditional validation rule support in laravel, see the below code to understand. 

request()->validate([
    'name' => 'required|string|min:6',
    'password' => [
        'required',
        'string',
        Rule::when(true, ['min:5', 'confirmed'])
    ],
]);

 

In the above code example, the min:5 and confirmed validation rules only apply when the first argument of Rule::when() is true.

 

Facebook Github
A web enthusiastic, a self-motivated full-stack software engineer from Dhaka, Bangladesh with experience in developing applications using Laravel , React and Vue js