how to fail Laravel validate if extra param pass to it?

1k Views Asked by At

I'm using Laravel validation for validate user request. it's work for me but I need to validation failed if user send any parameter more than that mentioned in rules. for example if the rule is like this:

['id'=>'required|integer']

if user send anything extra like

'name'=>'foo'

the validation should failed and the error message is something like:

the name param is not allowed.
1

There are 1 best solutions below

0
Daud khan On

You can write a custom validation rule or you can do

if(!in_array("name", $request->all())){
    return redirect()->back()->with('errorMessage','the name param is not allowed.')->withInput();
}

and to show an error message in blade file

@if (session('errorMessage'))
    {{ session('errorMessage') }}
@endif