Search code examples
laravelrequestlaravel-5.3

use Request's rules to refuse a specific value


i m new with laravel 5.3. i have a form and i want to show an error if a user tape a specifique caracter

for exemple if user tape 0 and click on submit, an error will be shown

I m trying to do it by setting rules for my Request for exemple :

    class calcRequest extends Request
{
    public function authorize()
    {
        return true;
    }


    public function rules()
    {
        return [
            'num1'=>'required',
            'num2'=>'required',
            'op'=>'required'
        ];
    }
}

num2 should be diffrent from 0

How could i do it ? thnks


Solution

  • You can use not_in:0 . You can follow the example at there

    'num2' => 'required|not_in:0',