1

我试图让用户仅使用他们的national_id登录。我只需要使用他们的national_id登录/注册用户,如果存在则返回JSON true,如果不存在则释放令牌以将用户保存在移动设备中,这样他就不需要登录再次。这里是我编辑的登录/注册代码

更新

这是我到目前为止所达到的

 public function Authenticate(Request $request)
{


    $national_id = $request->input('national');

    $user = User::where('national_id', '=', $national_id)->first();

    if (!$userToken = JWTAuth::fromUser($user)) {
        return response()->json(['error' => 'invalid_credentials'], 401);
    }

    return response()->json(compact('userToken'));
}

} 我的路线

$api = app('Dingo\Api\Routing\Router');
$api->version('v1', function ($api) {
$api->post('auth/login', 'App\Api\V1\Controllers\AuthController@Authenticate');

当我测试这段代码时,我得到

"message": "Call to a member function first() on null",
"status_code": 500,
"debug": {

是否可以编辑此功能以用于登录/注册?提前感谢您的帮助。

4

0 回答 0