I'm using laravel-jsValidation, everything is working fine except Unique rule ! Here what I have : Rules :
protected $userValidate=[
'lastname' => 'required|max:100|min:2',
'firstname' => 'max:100|min:2',
'username' => 'required|unique:users|min:2',
'email' => 'required|unique:users|email|max:255',
'password' => 'required|confirmed|min:6', ];
Get Users List Function :
public function getUsers(){
$validator = JsValidator::make($this->userValidate);
return view('admin.usersList')->withValidator($validator);}
Store Function :
public function store(Request $request){
$data = $request->all();
$v = Validator::make($data, $this->userValidate);
if ($v->fails())
{
return redirect()->back()->withErrors($v->errors());
}
$user = User::create([
'lastname' => $data['lastname'],
'firstname' => $data['firstname'],
'username' => $data['username'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'confirmed' => 1,
]);
return redirect('admin/usersList');}
The problem is when I enter username or email, an error message appears under its input in form:
Whoops, looks like something went wrong.
NB : I set : 'disable_remote_validation' => false, and when I change it to true, it works fine only if I enter username and email which don't exist in users table !
What's the mistake in my code ?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire