jeudi 19 novembre 2020

Login not working in Laravel using vue.js

I'm trying to Login using Laravel and Vue.js its controller code is:

  public function login(Request $request){ 

        $validation = Validator::make($request->all(),[
            'user_id' => 'required|email',
            'password' => 'required|string|min:8|max:15',
        ]);

        if ($validation->fails()) {
            $response['status'] = false;
            $response['message'] = $validation->errors()->first();
            return response()->json($response,200);
        }

        if(Auth::attempt(['email' => request('email'), 'password' => request('password')])){ 
            $user = Auth::user(); 
            $token =  $user->createToken('MyApp')->accessToken;  
   
            $user->api_token = $token;
            $user->save();
          
            return response()->json([
                'status'=>true,
                'message' => 'Login successfully',
                'user' => $user,
            ], 200); 
        } 
        else{ 
            return response()->json(['status'=>false,'message' => 'Invalid Login'], 200);
        } 

    }

but i'm getting Invalid Login message



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3nC1Num
via IFTTT

Aucun commentaire:

Enregistrer un commentaire