5

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

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Now you can use when method:)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.