Advertisement
Guest User

UserController@login

a guest
Aug 13th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.54 KB | None | 0 0
  1. // route
  2. $router->post('login', 'UserController@login');
  3.  
  4. public function login(Request $request)
  5.     {
  6.         // Validation Stuff
  7.  
  8.         $email = $request->email;
  9.         $pass =  $request->password;
  10.  
  11.         $user = User::where('email' , $email)->first();
  12.  
  13.         if ( Hash::check($pass, $user->password) ) {
  14.  
  15.             $token =  $user->createToken('User Token', ['*'])->accessToken;
  16.             return $this->sendResponseApiToken($token);
  17.         }
  18.  
  19.         // if unauthorized
  20.         return $this->sendUnauthorizedResponse();
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement