B
B
Boooom2019-05-19 20:43:09
Laravel
Boooom, 2019-05-19 20:43:09

Combining two queries and outputting them to pagination how?

How to combine two requests in the controller and then display them in pagination?
In the view, there is no particular desire to do two pieces of forich
Example:

$goods1 = Goods::where('siteID', $siteID)->where('popular', 1)->get();
$goods2 = Goods::where('siteID', $siteID)->where('popular', 2)->get();

vivod = goods1 + goods2 ->paginate(12)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
NubasLol, 2019-05-20
@boooom

$goods1 = Goods::where('siteID', $siteID)->where('popular', 1);
$goods2 = Goods::where('siteID', $siteID)->where('popular', 2);

 $vivod = $goods1->unionAll($goods2)->paginate(12);

J
JhaoDa, 2019-05-19
@JhaoDa

Have you read the documentation on collections ?
Although I see that I need to read the Query Builder documentation, because if both queries return at least a hundred options, then it will be fun.

D
dk-web, 2019-05-20
@dk-web

$goods = Goods::where('siteID', $siteID)->whereIn('popular', ['1','2'])->paginate(12);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question