Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are There Relationships? #3

Open
timgavin opened this issue Jul 1, 2022 · 0 comments
Open

Are There Relationships? #3

timgavin opened this issue Jul 1, 2022 · 0 comments

Comments

@timgavin
Copy link

timgavin commented Jul 1, 2022

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant