如何在Laravel中使用自定义查询实现无限滚动?类似于:
$query = Select * from table join table2 on condition where condition order by c1 ;
$l = DB::select($query)->paginate(12);我有5个字段国家,地区,城市,类别和price_range。用户可以通过字段1到5中的任何一个进行搜索。然后我有一些其他的url参数,如排序。
因此,如果我使用自定义查询,那么我可以连接从url接收到的值,并一次性运行查询。
这就是我所想的场景。最终的查询将看起来像我在上面发布的。
提亚
发布于 2017-01-25 12:13:10
对于您的情况,您可以像这样链接条件:
$query = DB::table('table1')
->join('table2', 'table1.id', '=', 'table2.table_id');
if ( $request->has('state') && $request->state != '' ) {
//We have a state in the query and it's not empty
$query->where('table1.state', '=', $request->state);
}
if ( $request->has('region') && $request->region != '' ) {
//We have a region in the query and it's not empty
$query->where('table1.region', '=', $request->region);
}
//We finished checking all our conditions
//Finishing the query now...
$l = $query->paginate(12);https://stackoverflow.com/questions/41843201
复制相似问题