mercredi 30 décembre 2015

union query in laravel 5

My regular query is like this :

select "tb_news"."id" as "id", "tb_news"."title" as "title", "tb_news"."content" as "content" 
from "tb_news" 
where "tb_news"."id"  = 95
union 
select "tb_news_two"."id" as "id", "tb_news_two"."title" as "title", "tb_news_two"."content" as "content" 
from "tb_news_two"
where "tb_news_two"."id"  = 95 

I change the regular query to a query laravel.

My laravel query is like this :

$news_two = DB::table('tb_news_two')->select('tb_news_two.id AS id','tb_news_two.title AS title ','tb_news_two.content AS content')
                                   ->where('tb_news_two.id',$news_id);
$news = DB::table('tb_news')->select('tb_news.id AS id','tb_news.title AS title ','tb_news.content AS content')
                                 ->union($news_two)
                                 ->where('tb_news.id',$news_id);

But, My laravel query not working.

How do I use the unions in laravel with where ?

Thank you



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

Aucun commentaire:

Enregistrer un commentaire