如何在laravel 5中结合查询?

时间:2015-12-30 22:11:14

标签: laravel laravel-5 union

我的常规查询是这样的:

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 

我将常规查询更改为查询laravel。

我的laravel查询是这样的:

$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);

但是,我的laravel查询不起作用。

如何在laravel中使用where

来使用工会

谢谢

0 个答案:

没有答案