laravel-6

how to validate a field that must be false in laravel form request


I want to set ('is_color' = false) if ('is_variation' = true) in form request

        $rules  = [
            'is_color'                      =>  'nullable|boolean',
            'is_guarantee'                  =>  'nullable|boolean',
            'is_variation'                  =>  'nullable|boolean',
        ];

Solution

  • It seems not related to the validation, What I found out is you want set is_color due to is_variation's value, so you can validate just is_variation and set is_color. But you can validate these parameter related to each other with make a method named withValidator in your form request. For more information you can see below link: With Validator

    Or you can make custom rule validation : Custom Validation in laravel