I have several models chained by 1:N relationships:
User (1 -> N) Asignatura (1 -> N) Clase (1 -> N) Asiento
I want to obtain a collection of Asiento models, containing all the Asientos of a User.
I tried the "obvious"
$user->asignaturas->clases->asientos;
but as $user->asignaturas is a collection, ->clases is not recognized as a valid method (all due relationships, asignaturas(), clases() and asientos() has been created in their respective models)
So I did the following to solve the problem:
$user = User::findorFail(Auth::user()->id);
$asignaturasArr = $user->asignaturas->pluck('id')->toArray();
$clases = Clase::whereIn('asignatura_id', $asignaturasArr)->get();
$clasesArr = $clases->pluck('id')->toArray();
$asientos = Asiento::whereIn('clase_id', $clasesArr)->get();
but I suspect that Laravel should have a less verbose way to do the work, and I am not being able to find it.
I will be grateful to have any advice from any expert.
Thank you very much in advance and best regards.