File tree Expand file tree Collapse file tree 4 files changed +23
-3
lines changed
Expand file tree Collapse file tree 4 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -340,7 +340,16 @@ public function getQualifiedFieldName(string $field): string
340340 */
341341 public function getRelationModelClass (string $ relation ): string
342342 {
343- return get_class ((new $ this ->resourceModelClass )->$ relation ()->getModel ());
343+ $ relations = collect (explode ('. ' , $ relation ));
344+ $ relation = $ relations [0 ];
345+
346+ $ resourceModel = (new $ this ->resourceModelClass )->$ relation ()->getModel ();
347+
348+ foreach ($ relations ->skip (1 ) as $ nestedRelation ) {
349+ $ resourceModel = $ resourceModel ->$ nestedRelation ()->getModel ();
350+ }
351+
352+ return get_class ($ resourceModel );
344353 }
345354
346355 /**
Original file line number Diff line number Diff line change @@ -108,4 +108,16 @@ public function getting_a_single_resource_with_included_relation(): void
108108
109109 $ this ->assertResourceShown ($ response , $ post ->fresh ('user ' )->toArray ());
110110 }
111+
112+ /** @test */
113+ public function getting_a_single_resource_with_nested_included_relation (): void
114+ {
115+ $ post = factory (Post::class)->create (['user_id ' => factory (User::class)->create ()->id ]);
116+
117+ Gate::policy (Post::class, GreenPolicy::class);
118+
119+ $ response = $ this ->get ("/api/posts/ {$ post ->id }?include=user.roles " );
120+
121+ $ this ->assertResourceShown ($ response , $ post ->fresh ('user.roles ' )->toArray ());
122+ }
111123}
Original file line number Diff line number Diff line change @@ -58,6 +58,6 @@ public function exposedScopes(): array
5858 */
5959 public function includes (): array
6060 {
61- return ['user ' ];
61+ return ['user ' , ' user.roles ' ];
6262 }
6363}
Original file line number Diff line number Diff line change @@ -42,7 +42,6 @@ public function roles()
4242
4343 public function notifications ()
4444 {
45- // $this->roles()->whereDate()
4645 return $ this ->belongsToMany (Notification::class)->withPivot ('meta ' );
4746 }
4847}
You can’t perform that action at this time.
0 commit comments