Teams: Get all roles with count of users. #2013
-
Hello, I am currently building a SaaS application where a team can have multiple roles, this package seemed like a perfect fit for my use case. I can get out all the roles for a specific team with the following eloquent query:
As soon as I try to eager load the users with the roles like this:
I get the following error: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'team_id' in where clause is ambiguous (SQL: select I am not sure if this is an issue with the package or If I have misconfigured something when I set up the team's part on installation. Any help is greatly appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I tried Looks at this laravel-permission/src/Models/Role.php Lines 72 to 81 in 6a3ed62 there is no team_id = 1) on relationship, you did add that on some place and them it is ambiguous because you did add team_id on user model, add table name for that where for fix that
Also why put team_id on user? public function teams()
{
return $this->belongsToMany(Teams::class, 'team_has_users');
} |
Beta Was this translation helpful? Give feedback.
I tried
$roles = Role::where('team_id', MY_TEAM_ID)->with('users')->get();
and everything works as expected, maybe you broke something on your implementation
Looks at this
laravel-permission/src/Models/Role.php
Lines 72 to 81 in 6a3ed62
there is no
team_id = 1)
on relationship, you did add that on some place and them it is ambiguous because you did addteam_id
on …