与Laravel中的查询返回错误的时间戳记一起使用 [英] Join with where query in Laravel returns wrong timestamps

查看:145
本文介绍了与Laravel中的查询返回错误的时间戳记一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

奇怪的事情发生了,我用以下命令查询:

Strange thing happens, I query with the following:

$bananafriends   = IsFree::join('friendships', function($join)use($user) {
                    $join->on('arefree.user_id', '=', 'friendships.user_rec_id')
                        ->where('friendships.user_send_id', '=', $user->id); 
                    })
                    ->get();

它返回时间戳&友谊模型的ID,但不是isFree模型的ID。
如果不起作用,我不明白为什么或如何从isFree模型中检索时间戳。

It returns the timestamps & ID of the friendship model but not the isFree model. I don't understand why or how I could retrieve the timestamps from the isFree model if that does not work.

谢谢!

推荐答案

现在,选择区域相互覆盖。

Right now the selects are overriding each other.

您需要添加选择区域:

You need to add a select:

$bananafriends = IsFree::join('friendships', function($join)use($user) {
                    $join->on('arefree.user_id', '=', 'friendships.user_rec_id')
                        ->where('friendships.user_send_id', '=', $user->id); 
                    })
                    ->select('friendships.*', 'arefree.*', 'arefree.created_at as free_created')
                    ->get();

请参阅文档:

http://laravel.com/docs/4.2/queries#selects

如果这不起作用,请告诉我,我将帮助您解决问题。

If this does not work let me know I will help you troubleshoot it.

这篇关于与Laravel中的查询返回错误的时间戳记一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆