A
A
Anton Shelestov2020-12-28 13:18:53
Laravel
Anton Shelestov, 2020-12-28 13:18:53

Get relation based on parent id?

Hello!

Perhaps the question is not very clear, but I will try to explain with an example.
There is a code:

$specialities = Speciality::with([
            'educationals' => function ($query) {
                return $query->with([
                    'specialities' => function ($query) {
                        //dd($query);
                        //return $query->where('speciality_id', $speciality->id);
                    }
                ])
                    ->take(3);
            }
        ])
            ->paginate(10);


Here we get a list of specialties, in each we get a maximum of 3 educational institutions where this specialty exists (the limit for relations is implemented through a separate package). And then for each UZ you need to get the data of this specialty (not the entire list of specialties that are in this UZ) from the UZ

. Is it possible to do this?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question