Laravel 4 and Eloquent: retrieving all records and all related records

南笙酒味 提交于 2019-12-03 08:58:57

Your model relationships are fine.

Controller:

$artists = Artist::with('instruments')->get();

return \View::make('artists')->withArtists($artists);

View:

@foreach ($artists as $artist)

    <h1>{{ $artist->firstname }}</h1>

    @foreach ($artist->instruments as $instrument)

        <h2>{{ $instrument->name }}</h2>

    @endforeach

@endforeach
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!