validate form with laravel

0

Hello, I am trying to validate the fields of the form that I created with the validate function of laravel, I pass valid data to it and it does not validate.

 $request->validate([
            'player' => 'alpha_dash',
            'spec.*' => 'integer|distinct|min:2',
            'realm' => 'alpha_dash',
            'faction' => 'alpha',
        ]);

It's strange because the player field validates me but realm and faction do not. I am introducing values such as Alliance, Horde, Both a faction or Kingdom names with alpha to realm characters.

    
asked by Akond 03.11.2017 в 08:12
source

1 answer

-1

It was happening because the player and spec field were empty and therefore he did not validate hehe.

I had to add the nullable clause to the validation:

$request->validate([
            'player' => 'nullable|alpha_dash',
            'spec.*' => 'nullable|integer|distinct|min:2',
            'realm' => 'alpha_dash',
            'faction' => 'alpha',
        ]);

greetings

    
answered by 03.11.2017 в 08:28