user

Joseph Morgan

18 Feb 2022

Method Illuminate\Validation\Validator::validateRequried does not exist.

Laravel

Hello everyone I am facing this error with laravel when I use the condition $validator->fails(); my code is 

 public function login(Request $req){
 $validator = Validator::make($req->all(), [
 'email' => 'required|email',
 'password' => 'requried',
 ]);

 if ($validator->fails()) {
 return response()->json($validator->errors(), 400);
 }

 if(Auth::guard('regular_users')->attempt(['email' => request('email') , 'password' => request('password')])){
 $token = Str::random(60);
 $request->user()->forceFill([
 'api_token' => hash('sha256', $token),
 ])->save();
 return response()->json([ "token" => $token ], 200);
 } else {
 return response()->json(['Error'], 400);
 }
 }

What is problem please help!

Comments

Mohamed Atef

18 Feb 2022

Best Answer

best answer
githubgithubgithub

there is no problem with the condition the only problem is in your typo of required your code is

 $validator = Validator::make($req->all(), [
 'email' => 'required|email',
 'password' => 'requried',
 ]);

can you note “requried” correct the typo to be “required” so you need to change your condition to 

 $validator = Validator::make($req->all(), [
 'email' => 'required|email',
 'password' => 'required',
 ]);

Good luck

© 2024 Copyrights reserved for web-brackets.com