user image

Joseph Morgan
Published in : 2022-02-18

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 Date : 2022-02-18

Best answers

46

Best answers

46

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

Leave a comment

Join us

Join our community and get the chance to solve your code issues & share your opinion with us

Sign up Now

Related posts

How can I validate recaptcha in Livewire class ??
Publish date: 2022-02-23 | Comments: 2
Get user location (city - country) from his IP address
Publish date: 2022-03-02 | Comments: 2
How to pass valiables to 404 error page in laravel?
Publish date: 2022-02-21 | Comments: 2
call_user_func() expects parameter 1 to be a valid callback
Publish date: 2022-02-22 | Comments: 2
Laravel clear cache files manually
Publish date: 2022-03-02 | Comments: 2
[solved] All assets in laravel storage returns 404
Publish date: 2021-12-14 | Comments: 2
Uncaught Error: Missing required parameters: sitekey Laravel
Publish date: 2022-01-08 | Comments: 2