I am trying to union 2 tables (recipes + posts) and add ->paginate(5) to the queries.
But for some reason i get this error:
Cardinality violation: 1222 The used SELECT statements have a different number of columns (SQL: (select count(*) as aggregate from
posts
My code:
$recipes = DB::table("recipes")->select("id", "title", "user_id", "description", "created_at")
->where("user_id", "=", $id);
$items = DB::table("posts")->select("id", "title", "user_id", "content", "created_at")
->where("user_id", "=", $id)
->union($recipes)
->paginate(5)->get();
Am i doing something wrong?
- Without ->paginate(5) the query works fine.