Answers for "how auth with api in laravel"

PHP
0

Laravel api login

public function login(Request $request){
        $fields = $request->validate([

         'email'=>'required|string|email',
         'password'=>'required|string'   
        ]);

        //Check email

        $user= User::where('email', $fields['email'])->first();

        //Check Password
        if(!$user || !Hash::check($fields['password'], $user->password) ){
            return response([
                'message'=>'Invalid Credentials'
            ], 401);
        }

        $token = $user->createToken('myapptoken')->plainTextToken;

        $response= [
            'user' => $user,
            'token'=> $token
        ];

        return response($response, 201);
    }
Posted by: Guest on August-02-2021
-1

how auth with api in laravel

$data = $request->all();
Auth::attempt(['email'=>$data['email'] , 'password'=>$data['password']])
Posted by: Guest on June-18-2021

Browse Popular Code Answers by Language