I'm working on an app, where I should be performing search on a table containing users. However, I cannot figure out how to correctly compose the route in order to attach the view with the controller and back. My code is the following: The view:
<form action='' method='GET'> <input class='form-control' type="text" name="keyword" placeholder="Search for user..."> </form>
The route: Route::get('users?keyword={$keyword}', 'UsersController@search');
The search() in UsersController:
`public function search() { $keyword = Request::get('keyword');
$users = User::where("username", "LIKE","%$keyword%")
->orWhere("firstname", "LIKE", "%$keyword%")
->orWhere("lastname", "LIKE", "%$keyword%")
->orWhere("email", "LIKE", "%$keyword%")
->orWhere("phone", "LIKE", "%$keyword%")-get();
return view('search', compact('users'));
}`
Can someone please tell what would be the correct syntax? Thanks in advance!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire