Пример #1
0
 /**
  * Login and return profile data
  *
  * @param  Request $request
  * @return Response
  */
 public function login_profile(Request $request)
 {
     $credentials = $request->only('email', 'password');
     //$credentials = $request->all();
     try {
         // attempt to verify the credentials and create a token for the user
         if (!($token = JWTAuth::attempt($credentials))) {
             return response()->json(['error' => 'invalid_credentials'], 401);
         }
     } catch (JWTException $e) {
         //dd($token);
         // something went wrong whilst attempting to encode the token
         return response()->json(['error' => 'could_not_create_token'], 500);
     }
     //dd($token);
     // the token is valid and we have found the user
     $user = Auth::user();
     try {
         $profile = Profile::byuser_id($user->id)->firstOrFail();
         //$industry = [$profile->industry->slug, $profile->industry->name];
         //return response()->json(compact('token', 'profile', 'industry'));
         return response()->json(compact('token', 'profile'));
     } catch (ModelNotFoundException $e) {
         return response()->json(['error' => 'profile does not exist'], 404);
     }
 }