How do I perform a Laravel unique validation on multiple columns for unique relations.
One user can add new games but I want it so that one user cannot add new identical games
For example, I don't want to allow this: - table games - id name user_id - 1 Descent 1 - 1 Descent 1
But I want to force the users this:
How do I do this in laravel? I apologise for the messy formatting, I can't seem to get it to work
Try the unique rule with with additional where clause
'name' => 'unique:games,name,NULL,id,user_id,'.$user->id
If using auth:
public function rules() {
return [
'email' => 'required|email|unique:users,email,NULL,id,deleted_at,NULL,department_id,' . auth()->user()->department_id,
];
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community