I am trying to grab collections form many to many relationships in my application.
To explain very quickly: Lets say I have categories that themselves have dedicated hashtags. Those hashtags again have photos.
Now, I want to grab one category and its dedicated hashtags. But I also want to grab all photos that are associated with those hashtags.
So here is what I have tried but still, this does not work:
$all_related_hashtags = $categorie->hashtags()->get();
$photos = foreach ($all_related_hashtags as $hashtag) {
$hashtag->photos;
}
Is there any way to fix this?
Any help would be awesome.
Thanks.
EDIT
@foreach ($all_related_hashtags as $hashtag)
@foreach(array_chunk($hashtag->photos, 4) as $row)
<div class="row">
@foreach($row as $photo)
SECOND EDIT
@foreach ($all_related_hashtags as $hashtag)
@foreach ($hashtag->photos as $photo)
{{ $photo->title }}
@endforeach
@endforeach