Search code examples
laravelvalidationvalidationrules

How to validate the laravel input for spoofed input field name?


I have a input field as:

<input type="email" name="email" />

And it works fine with the laravel validation rules as:

 $rules = [
        'email' => 'email|required',
]

But if someone changes the HTML input field name using console something like:

 <input type="email" name="email[]" />

Laravel does not catch the validation and returns an error: enter image description here

Is there any better way to handle such input manipulation in laravel?

Thanks for the help!


Solution

  • you can use

    $rules = [
        'email.*' => 'email|required',
      ]
    

    this will validate each items in array

    refer https://laravel.com/docs/5.6/validation#validating-arrays