【问题标题】:Where on hadOne linked table with Laravel Eloquent ORM使用 Laravel Eloquent ORM 在 hadOne 链接表上的位置
【发布时间】:2014-06-06 17:50:55
【问题描述】:

我在 Laravel 模型中使用 hasOne 加入了用户表。我想对连接的表数据使用 where 语句。这可以使用 Eloquent ORM 吗?

    $episode = Episode::where('uri', Input::get('episode'))
                        ->where('public', true, 'OR') // Return public or:
                        ->where('user.id', $->id) // Own user events
                        ->first();



    $episode = Episode::where('uri', Input::get('episode'))
                        ->where('public', true, 'OR') // Return public or:
                        ->user()->where('id', $id) // Own user events
                        ->first();

【问题讨论】:

    标签: php mysql laravel laravel-4 eloquent


    【解决方案1】:

    我在 Laravel 4.1 中从 this other stackoverflow question 找到了答案。

        $episode = Episode::where('uri', Input::get('episode'))
                            ->where('public', true, 'OR') // Return public or:
                            ->whereHas('user', function($q)
                            {
                                $q->where('id', '=', $this->user->id);
    
                            }) // Own user events
                            ->first();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-07
      • 1970-01-01
      • 2016-02-11
      • 2014-09-30
      • 2016-03-16
      • 1970-01-01
      • 2013-01-22
      相关资源
      最近更新 更多