Joseph Morgan
Published in : 2022-02-18
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!
Join our community and get the chance to solve your code issues & share your opinion with us
Sign up Now
Mohamed Atef Date : 2022-02-18
Best answers
51
Best answers
51
there is no problem with the condition the only problem is in your typo of required your code is
can you note “requried” correct the typo to be “required” so you need to change your condition to
Good luck