i'm using jQuery modal for user create and update for my laravel project. when creating new user im checking the username availaibilty. but that function doesnot support with update , when user save data without changing username it gives usernam availble error . please advice how to fix
my controller,
public function checkUsernameAvailability() {
$user = DB::table('users')->where('username', Input::get('username'))->count();
if ($user > 0) {
$isAvailable = FALSE;
} else {
$isAvailable = TRUE;
}
echo json_encode(
array(
'valid' => $isAvailable
));
}
jQuery modal
username: {
validators: {
notEmpty: {
message: 'The Username field is required'
},
rules : {
username : { alphanumeric : true }
},
remote: {
url: "{{ URL::to('/checkUsername') }}",
data: function (validator) {
return {
username: validator.getFieldElements('username').val()
}
},
message: 'The Username is not available'
},
stringLength: {
max: 100,
message: 'The Username must be less than 100 characters long'
}
}
},
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1NKQhXI
via IFTTT
Aucun commentaire:
Enregistrer un commentaire