laravel-follow icon indicating copy to clipboard operation
laravel-follow copied to clipboard

Are There Relationships?

Open timgavin opened this issue 2 years ago • 0 comments

I'm getting a list of the logged in user's followers, and it's only returning each follower's ID

auth()->user()->followings

So in order to get the follower's names, I need to do a separate query.

$ids = [];
foreach (auth()->user()->followings as $followed) {
    $ids[] = $followed->followable_id;
}

$this->following = User::whereIn('id', $ids)->get();

Is this the correct way? Or are there relationships defined and just not documented? Am I missing something?

The expected behavior to me would be like this

@foreach(auth()->user()->followings as $user)
    {{ $user->name }}
@endforeach

timgavin avatar Jul 01 '22 11:07 timgavin