我有一个搜索表单和功能,全部完成。只是想问一下,是否可以在 Eloquent 中进行这样的查询:
SELECT * FROM players WHERE name LIKE '%".$name."%'
显示一些可能的匹配名称。我当前的 Controller 功能:
public function search()
{
$name = Input::get('character');
$searchResult = Player::where('name', '=', $name)->paginate(1);
return View::make('search.search')
->with('name', $name)
->with('searchResult', $searchResult);
}
我的看法:
<form id="custom-search-form" class="form-search form-horizontal pull-right" action="{{ URL::action('CharactersController@search') }}" method="get">
<div class="input-append spancustom">
<input type="text" class="search-query" name="character" placeholder="Character/guild name">
<button type="submit" class="btn"><i class="icon-search"></i></button>
</div>
</form>
提前致谢。
最佳答案
嗯,是的,只需将 like
设置为您的比较运算符,并发送带有 %
的字符串。像这样:
Player::where('name', 'LIKE', "%$name%")->get();
关于php - Laravel 4/5 搜索表单,如,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18283714/