【问题标题】:Join with where query in Laravel returns wrong timestamps在 Laravel 中加入 where 查询返回错误的时间戳
【发布时间】:2015-02-02 22:59:47
【问题描述】:

奇怪的事情发生了,我查询如下:

$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 模型。 如果这不起作用,我不明白为什么或如何从 isFree 模型中检索时间戳。

谢谢!

【问题讨论】:

    标签: php mysql laravel eloquent


    【解决方案1】:

    现在选择相互覆盖。

    你需要添加一个选择:

    $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

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

    【讨论】:

    • 谢谢!!不需要最后一个 arefree.created_at。一旦你选择了 arefree.*,它就需要时间戳!非常感谢你:-)
    猜你喜欢
    • 2020-11-23
    • 2021-09-15
    • 2020-07-03
    • 2017-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多