首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Laravel中使用自定义查询实现无限滚动?

问如何在Laravel中使用自定义查询实现无限滚动?
EN

Stack Overflow用户
提问于 2017-01-25 12:04:49
回答 1查看 173关注 0票数 0

如何在Laravel中使用自定义查询实现无限滚动?类似于:

代码语言:javascript
复制
$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接收到的值,并一次性运行查询。

这就是我所想的场景。最终的查询将看起来像我在上面发布的。

提亚

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-25 12:13:10

对于您的情况,您可以像这样链接条件:

代码语言:javascript
复制
$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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41843201

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档