Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 PHP - filter results with input value

I have this where I get all my tournaments $tournaments = Tournament::all();. Now I want to let the user filter these on the go in the view... I would like to have an <input> where the user enters a few characters and then the results filter on tournaments that have those characters in the name.

I have found this* online but I dont know how to populate that $keyword. It would be best if the results filter after every character that is entered in the inputfield. If this is not possible, then make this a form that sends this $keyword to Controller and retrieves the new results on the same page!
* $tournament = Tournament::where('name', 'LIKE', '%'.$keyword.'%')->get();

How do I do this? I don't know... Please provide some code in the answer.

Thx

like image 901
nclsvh Avatar asked Jan 14 '16 20:01

nclsvh


1 Answers

Are you wondering how to get the input of a posted value? You can use the Input::get() method.

$keyword = Input::get('keyword');
if(isset($keyword)){
   $tournaments = Tournament::where('name', 'LIKE', "%$keyword%")->get();
}else{
   $tournaments = Tournament::all();
}

Also can also use jQuery UI Autocomplete function to progressively search for results.

like image 182
whobutsb Avatar answered Oct 21 '22 04:10

whobutsb