I'm using laravel-jsValidation, https://github.com/proengsoft/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 ?
I think the problem is : this package does not support remote validation, as I can read in Config/jsValidation.php :
/* * Enable or disable Ajax validations of Database and custom rules. * By default Unique, ActiveURL, Exists and custom validations are validated via AJAX */ 'disable_remote_validation' => false,
So how can I validate this rule via AJAX ? please is there any tutorial ?