Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 2 years ago.
0

I think it is something like this,

$this->data['item'] = Album::where('album_id', '=', $id)->where('user_id','=',Auth::user()->user_id)->with("photo")->with("photo.tags")->first();
0

Hello.
TerrePorter shows how to eager load the needed data, use that approach. To show it in the view make something like

<h2>Album {{$album->name}}</h2>
@foreach($album->photo as $photo)
<div>
<img src="{{$photo->url}}"/>
Tags:
@foreach($photo->tags as $tag)
{{$tag->name}}
@endforeach
</div>
@endforeach

$photo->tags is a collection (not array). You have to foreach it to access each element.

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

fishball fishball Joined 26 Dec 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.