Answer the question
In order to leave comments, you need to log in
How to make a union request in laravel so that pagination works?
Good afternoon, I'm trying to make a request on laravel in order to get products from child categories and the category itself in the output. Here is the request itself:
$first = Product::where('status', 1)
->where('category_id', $catalog->id);
$load_product = Product::where('status', 1)
->whereIn('category_id', Catalog::select('id')->where('parent_id', $catalog->id)->get())
->union($first)
->paginate();
SQLSTATE[21000]: Cardinality violation: 1222 The used SELECT statements have a different number of columns (SQL: (select count(*) as aggregate
Answer the question
In order to leave comments, you need to log in
Why is union here? After all, you can do everything with one request, something like this:
$load_product = Product::where('status', 1)->where(function($query) use($catalog)
{
return $query->where('category_id', $catalog->id)
->orWhereIn('category_id', Catalog::where('parent_id', $catalog->id)->pluck('id'));
}
->paginate();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question