Well, in resource (School) I've tried to load nested relationship something like this:
'students' => UserResource::collection($this->whenLoaded('classes.user')) but without success.
School has many classes. Class can have many students. One student can be only in one class.
I wish to return all students that are in particular school.
Is this possible using Eloquent API resource or do I need to make custom response?
That won't work for this case as one student can be in one class in one school. But can also be another class in another school which means that student can be in multiple schools so adding school_id won't work.
But thank you for your suggestion.
I was just wondering will whenLoaded method work with nested relationship. As I could see from the code of whenLoaded function, it only accept one relationship as string.
Hi @integrasolid
This project was long time ago and I don't work on it anymore so I'm not sure to be honest, but as I could remember, I've used different approach/logic to solve this problem. As I could remember, this nested relationship in resource didn't work at that point.