Authentication with JWT Laravel 5 without password

后端 未结 3 625
陌清茗
陌清茗 2021-02-05 09:17

I\'m trying to learn Laravel and my goal is to be able to build a RESTful API (no use of views or blade, only JSON results. Later, an AngularJS web app and a Cordova hybrid mobi

3条回答
  •  情书的邮戳
    2021-02-05 09:47

    try with this:

    $user=User::where('email','=','user2@gmail.com')->first();
    
    if (!$userToken=JWTAuth::fromUser($user)) {
                return response()->json(['error' => 'invalid_credentials'], 401);
            }
    
    return response()->json(compact('userToken'));
    

    it works for me, hope can help

提交回复
热议问题