Validation rule unique requires at least 1 parameters

Candra Herk picture Candra Herk · Jan 31, 2018 · Viewed 22.8k times · Source

I've got problem with my laravel I can't post the data

One error says

InvalidArgumentException in Validator.php line 2593:
Validation rule unique requires at least 1 parameters.

And here it's my code

public function postUbah(Request $request, $id)

    $validator  = Validator::make($request->all(), [
            'username'  => 'required|unique:user|min:5',
            'name'      => 'required',
            'group'     => 'required'
        ]);
}

Thanks for the help.

Here it's my model

class User extends Model implements AuthenticatableContract, CanResetPasswordContract {

    use Authenticatable, CanResetPassword;


    protected $table = 'user';


    protected $fillable = ['username', 'password'];


    protected $hidden = ['password', 'remember_token'];

Answer

Sagar Gautam picture Sagar Gautam · Jan 31, 2018

You've forgot to add the parameter in validation rule to specify the database table column which should be unique in validation rule. You can do it like,

 $validator  = Validator::make($request->all(), [
        'username'  => 'required|unique:user,name|min:5',
        'name'      => 'required',
        'group'     => 'required'
    ]);