Laravel 5 PHP - 用输入值过滤结果 [英] Laravel 5 PHP - filter results with input value

查看:514
本文介绍了Laravel 5 PHP - 用输入值过滤结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我得到所有比赛的地方 $ tournaments = Tournament :: all(); 。现在我想让用户在视图中去的过滤这些...我想有一个< input> 用户输入几个字符,然后结果筛选名称中包含这些字符的锦标赛。



我发现这个* 在线,但是我不知道如何填充 $关键字。如果结果在输入字段中输入的每个字符之后过滤,那将是最好的。如果这是不可能的,那就把这个 $关键字发送给控制器,并在同一页面上检索新的结果 >
* $ tournament = Tournament :: where('name','LIKE','%'。$ keyword。'%') - > get();



我该怎么做?我不知道...请在答案中提供一些代码。

Thx

解决方案

您是否想知道如何获取已发布值的输入?您可以使用 Input :: get()方法。

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

也可以使用 jQuery UI Autocomplete 函数逐步搜索结果。

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

解决方案

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.

这篇关于Laravel 5 PHP - 用输入值过滤结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆