I'm doing a union on two queries, and I want to add a where clause to the result, but the where clause is added only to the first query. how can I fix that?
$notifications = DB::table('notifications')
->select(DB::raw("notifications.uuid ,notifications.brand_id" ))
$posts = DB::table('posts')
->select(DB::raw("posts.uuid ,posts.brand_id" ))
->unionAll ($notifications)
->orderBy('created_at' , 'desc')
->where('brand_ids' , '=' , '2')
$result = $posts->get();
I want this line
->where('brand_id' , '=' , '2')
to be added to the whole union, but it is added only to one of the queries.
->where('brand_id', '=', '2')
on both queries, and for the second before theunionAll
(and remove thebrand_ids
where clause) ? – Hierogram