0

The Query

$user_id = Auth::id();
$group_users = GroupUser::where('user_id', $user_id);
return view('groups.index', ['group_users' => $group_users]);

My Query has no errors

I need to list all rows from the group_users table with the the user ID that is equal to the

$user_id = Auth::id();

I am including the model with

use App\GroupUser;

And my table I am retrieving the data from has the following fields,

- group_id
- user_id
- user_role

And if I echo or print the

$user_id = Auth::id();

I get the correct user id. I'm not sure what I am missing.

2 Answers 2

3

GroupUser::where does not execute a query. To get results add get() chaining method:

$group_users = GroupUser::where('user_id', $user_id)->get();
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you it worked!!!! :D I will accept answer as soon as it lets me :D
0

GroupUser::where('user_id', $user_id) just return a builder.If you want return data you can fix :

$group_users = GroupUser::where('user_id', $user_id)->first(); to return first data

or

$group_users = GroupUser::where('user_id', $user_id)->get(); to return all data of table GroupUser

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.