Authenticate with username only Laravel 5.2

时间:2016-11-26 18:39:40

标签: laravel authentication laravel-5.2 jwt dingo-api

I'm trying to let user login with thier national_id only.All I need is to log/signup users with thier national_id, if exists then return JSON true if not then release token to save user in mobile so he doesn't need to login again.here the login/signup code that I edited

UPDATE

this is what I have reached so far

 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'));
}

} my route

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

when I test this code I get

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

is it possible to edit this function to be used for both login/signup? Thank you for the help in advance.

0 个答案:

没有答案