I'm trying to add aditional where clause in the unique validation rule. But before that, i need a join with other table. But I'm not being successful.
I have 2 Tables:
teams
with id, and name field
role_user_team
with role_id, user_id, and team_id being this three the key.
So i need to check if the teams.name field is unique for one specific user. I did try this:
'name' => Rule::unique('teams')->where(function ($query){
//return $query->where('account_id', 1);
return $query->join('role_user', 'role_user.team_id', '=', 'teams.id')->where('role_user', Auth::user()->id);
});
I know the problem is with the join but i don´t know how to solve it. Thank you!
Auth::id()instead ofAuth::user()->id. ObjectAuth::user()can not exists. - ventaquil