【问题标题】:Laravel 4 : How to combine where and with in eloquent ORMLaravel 4:如何在雄辩的 ORM 中结合 where 和 with
【发布时间】:2014-10-11 13:37:45
【问题描述】:

我想要当前登录用户的 json 和他的清单。如何结合 ::where 和 ::with?

这给了我当前登录的用户:

$user = User::where('user_id', '=', Auth::user()->user_id)->get();

这给了我所有的用户和他们的清单:

$user = User::with('checklists')->get();

【问题讨论】:

    标签: php laravel orm laravel-4 eloquent


    【解决方案1】:

    User::with() 会返回一个 Eloquent 查询对象,所以

    $user = User::with('checklists')
        ->where('user_id', '=', Auth::user()->user_id)
        ->get();
    

    【讨论】:

      猜你喜欢
      • 2017-11-05
      • 2015-01-15
      • 1970-01-01
      • 1970-01-01
      • 2018-09-18
      • 1970-01-01
      • 2014-01-03
      • 2013-08-14
      • 1970-01-01
      相关资源
      最近更新 更多