我对Laravel来说有点新,并且喜欢这个框架,但是我想要一个完整的文本搜索工作,没有运气!我会让代码做解释......
我的控制器
public function search() {
$table = Table::searchFilter('Name');
return $tables;
}
我的模特
public static function searchFilter($data, $pageLimit = '5') {
$keyword = !is_array($data) ? array('+'.$data.'*') : $data;
$matchArray = array('name', 'country', 'Region');
$columns = array();
foreach($matchArray as $column)
{
$columns[] = $column;
}
$match = implode(',', $columns);
$result = self::whereRaw('MATCH('.$match.') AGAINST (? IN BOOLEAN MODE)', $keyword)
->paginate($pageLimit);
return $result;
}
返回
{"total":0,"per_page":5,"current_page":1,"last_page":0,"from":0,"to":0,"data":[]}
条目
非常感谢您的帮助!