Laravel 4.2联盟 [英] Laravel 4.2 union
本文介绍了Laravel 4.2联盟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于以下请求:
$gamer_id = DB::table('users_relations')->select('gamer_id')->where('user_id', '=', Auth::user()->id)->first();
$test_id = DB::table('users_relations')->select('gamer_id')->where('user_id', '=', 2)->first();
$results = $gamer_id->union($test_id)->get();
dd($results);
我有错误:
Symfony \ Component \ Debug \ Exception \ FatalErrorException
Call to undefined method stdClass::union()
有什么想法吗?谢谢!
P.S.文档-> http://laravel.com/docs/queries#unions
P.S. Documentation -−> http://laravel.com/docs/queries#unions
推荐答案
调用 first()
时,您 get()
并返回第一个结果.结果, $ gamer_id
不再是查询生成器,因此缺少联合功能.而是使用查询修饰符 take(1)
.
When you call first()
, you get()
and return the first result. $gamer_id
is no longer a query builder as a result, so it lacks the union function. Instead, use the query modifier take(1)
.
$gamer_id = DB::table('users_relations')
->select('gamer_id')
->where('user_id', '=', Auth::user()->id)
->take(1);
$test_id = DB::table('users_relations')
->select('gamer_id')
->where('user_id', '=', 2)
->take(1);
$results = $gamer_id->union($test_id)->get();
这篇关于Laravel 4.2联盟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文