这是我当前的查询:
$q = $request->q;
-- first table
$n_arr = news::where('title','like',$q)->orWhere('description','like',$q)->get();
-- second table
$p_arr = productions::where('title','like',$q)->orWhere('description','like',$q)->get();
如您所见,目前我通过两个不同的查询来做到这一点。但是现在我需要使用 ->paginate()
,所以我也需要一个查询来分页所有结果。我需要像 union
子句这样的东西。
换句话说,我需要结合上面这两个查询的结果。
我如何在 Laravel 中做到这一点?
最佳答案
做到这一点的一种方法是 create pagination manually .
另一种方法是使用 skip()
和 take()
两个查询中的方法以获取当前页面的结果。
$n_arr = news::where('title','like',$q)->orWhere('description','like',$q)->->skip($page * $perPage)->take($perPage)get();
$p_arr = productions::where('title','like',$q)->orWhere('description','like',$q)->skip($page * $perPage)->take($perPage)->get();
关于php - 如何在两个不同的表中进行搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40240521/