Laravel 4.1 Eager Loading Nested Relationships with Constraints

后端 未结 3 1738
一整个雨季
一整个雨季 2021-02-08 03:03

I am trying to get Eager-Loading nested relationships, with constraints, to work. Everyone seems to be giving the same example of eager-loading nested relationships:

<         


        
3条回答
  •  无人共我
    2021-02-08 03:32

    If the relations in the models are correct you can simply do:

    $user = User::with('posts.comments')->get();
    

    You can add as many relations as you want ( or up to the memory limit ;)).

    It also works with pivot tables.

提交回复
热议问题