Reputation: 17289
i'm using latest version of laravel
framework and i want to set unique
fields to validator class such as email.
this below rule dont work correctly.
My Rule:
$rules = array(
'name' => 'required',
'email' => 'required|email|unique:email',
'nerd_level' => 'required|numeric'
);
i want to have unique email to register users.
Upvotes: 0
Views: 367
Reputation: 3197
The first field after unique: should be the table name and the second field should be the column name if you want to specify it, if you dont specify it then the input filed name is used. http://laravel.com/docs/validation#rule-unique
Try this where Users is the name of the table you are storing your users in
$rules = array(
'name' => 'required',
'email' => 'required|email|unique:Users',
'nerd_level' => 'required|numeric'
);
if you want to specify the email field use this
$rules = array(
'name' => 'required',
'email' => 'required|email|unique:Users,email',
'nerd_level' => 'required|numeric'
);
Upvotes: 3