Support the ongoing development of Laravel.io →
Requests Database Eloquent
Last updated 1 year ago.
0

First, you can retreive the authenticated user with "Auth::user()" instead of "User::find(Auth::id())".

I don't see your posts relationship in your User mode, but still, images are associated for each post.

// Anywhere in your controller
$user = Auth::user();
$posts = $user->posts;
foreach($posts as $post) {
    $images = $post->images;
}
Last updated 9 years ago.
0

So is there no way to return this is one nice array like my original script did? It just did not include the images.

I've even tried the following.

$proofs = User::find(Auth::id())
            ->posts()
            ->each(function($row) {
                return $row->images()->get();
            })
            ->orderBy('id')
            ->paginate(15);
Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

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.