mardi 24 mai 2016

Laravel add where clause to union result

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.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1TTFWrR
via IFTTT

Aucun commentaire:

Enregistrer un commentaire