safriansah

ravel-auth-controller-logout

Oct 23rd, 2020
1,006
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public function logout(Request $request){
  2.     try {
  3.         //code...
  4.         $validator = Validator::make($request->all(), [
  5.             'token' => 'required',
  6.         ]);
  7.         if ($validator->fails()) {
  8.             return $this->getResponse(406, $validator->errors()->first());
  9.         }
  10.  
  11.         $token = Token::where('code', $request->token)->where('status', 1)->first();
  12.         if (!$token) {
  13.             return $this->getResponse(401, 'Token undefined');
  14.         }
  15.  
  16.         $token->status = 0;
  17.         $token->save();
  18.         if (!$token) {
  19.             return $this->getResponse(500);
  20.         }
  21.  
  22.         return $this->getResponse(200);
  23.     } catch (\Throwable $th) {
  24.         //throw $th;
  25.         return $this->getResponse(500);
  26.     }
  27. }
RAW Paste Data