dimanche 31 janvier 2016

Eager loading inside eager loading in Laravel Eloquent

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. enter image description here



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire