Answer the question
In order to leave comments, you need to log in
Why is there an error when validating a laravel rule?
I'm trying to verify the username and password, as a result, the error:
local.ERROR: Undefined offset: 0 {"exception":"[object] (ErrorException(code: 0)
Validator::extend('user_check', function($attribute, $value, $parameters, $validator) {
$userDatabase = new UserEloquent;
$user = $userDatabase->where('login', $value)->get();
if($user[0]['login'] == $value){
return true;
}
return false;
});
Validator::extend('passw_hash_check', function($attribute, $value, $parameters, $validator) {
$userDatabase = new UserEloquent;
$user = $userDatabase->where('hash_password', $value)->get();
if($user[0]['hash_password'] == $value){
return true;
}
return false;
});
$validator = Validator::make($request->all(), [
'login' => 'required|string|user_check|min:3',
'password' => 'required|string|passw_hash_check|min:3',
]);
Answer the question
In order to leave comments, you need to log in
// вместо этого
$userDatabase = new UserEloquent;
$user = $userDatabase->where('login', $value)->get();
// это
$user = DB::table('users')->select('id')->where('login', $value)->first();
if($user) return true;
return false;
// или
'login' => 'unique:users,login'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question