【发布时间】:2017-06-11 17:57:47
【问题描述】:
假设我们有一些这样的查询字符串:
?param1=val1&param2=val2&param3=val3..
我正在使用以下脚本,但我知道这不是标准的方法,最好的,实际上是我见过/做过的最糟糕的!
在数据库中搜索文件:
$data = [
'files' => File::orderBy('id','desc')->paginate(12),
];
//Adding query strings
if (!empty($request->search)) {
$replacement_data = [
'files' => File::where('name','LIKE',"%$request->search%")->paginate(12),
];
return view ("manage.Files.index")->withData(array_replace($data,$replacement_data));
}
else {
return view ("manage.Files.index")->withData($data);
}
现在我的问题很清楚了,如何在 SQL/Eloquent where 语句中使用这些查询字符串作为过滤器?
【问题讨论】:
-
使用 laravel 的作用域通过请求数据过滤文件
标签: php laravel search query-string