guimorlo
1 week ago
218
3
Laravel

Validation rules, compare input to some strings

Posted 1 week ago by guimorlo

I want to validate an input (named "tipo") value to be equal to "UCIR", "UR" or "USB"

This is what i have tried so far in a custom Request class:

public function rules()
    {
        return [
            'apelido' => 'required|min:2|max:50',
            'fabricante' => 'required|min:2|max:50',
            'modelo' => 'required|min:2|max:50',
            'placa' => 'required|min:7|max:9|unique:viaturas',
            'imagem' => 'image|mimes:jpeg,jpg,png',
            'tipo' => "required|same:UR,UCIR,USB", //here is my trouble
            'unidade' => 'required'
        ];
    }

The error message I get every time: "The tipo and u r must match."

I am a beginner with Laravel and I am very grateful for any help. TY

Please sign in or create an account to participate in this conversation.