Reputation: 295
How to use eager loading inside eager loading? I tried make query like this: Here is my query in controller:
$user_all = User::with('universitas_has_detil')
->whereHas('universitas_has_detil', function ($query) {
$query->where('jenjang_universitas_id_jenjang', 2)
})->get();
And here is my view:
@foreach($user->universitas_has_detil as $detil)
{{ $detil->jenjang_universitas->nama_jenjang }},
@endforeach
But the result is like this, and not efficient.
Upvotes: 2
Views: 395
Reputation: 295
I found the answer by my self, I should using Nested Eager Loading that describes in Laravel documentation
Upvotes: 3