After submitting the search form, it redirects to a blank page

632 views Asked by At

I have a multi-column search form inside the 'users.index' view. The form is as mentioned below:

<form method="get" action="{{route('search')}}">
   <input autocomplete="off" type="text" name="name">
   <input autocomplete="off" type="text" name="role">
   <select name="status">
      <option disabled selected>--</option>
      <option value="0">inactive</option>
      <option value="1">active</option>
   </select>
   <button type="submit">search</button>
</form>

And the route is this:

Route::get('/admin/users/search', 'Admin\Search\SearchUsersController@search')->name('search');

But whatever I write inside the search function of the controller, it returns nothing and redirects me to a blank page! Let 's imagine the controller is something like this :

class SearchUsersController extends Controller
{
    public function search(Request $request)
    {
        dd($request->all());
    }
}

I wonder why such a thing is happening. When I change the method of the form into Post and I determine two different routes, the problem is solved but it 's a search form and logically the method should be get.

2

There are 2 answers

0
Solmaz Ahmadi On BEST ANSWER

Eventually I found a solution. If you have resource routes in web.php file of your project, you should introduce new routes before resource ones.

0
Mohammad.Kaab On

You need to use csrf_field() or <input type="hidden" name="_token" value="'.csrf_token().'"> in your form.