Laravel 5.1 JWT Get the logged in user from custom table
<p>I have created inside a Laravel 5.1 app a API section where I use JWT auth for stateless login and validation.
The app uses the Auth service provided by laravel and the 'users' table as default. My API needs authentication on the 'clients' table. 
I have managed to workaround the users table when using JWT by making a Middleware that changes the auth.php config file to  <code>model =&gt; 'Models\AuthClient'</code> and <code>table =&gt; 'clients'</code>. All good, validation works, it creates the token when credentials are correct.</p>

<p>Middleware:</p>

<pre><code>public function handle($request, Closure $next)
{
    \Config::set('auth.model', 'App\Models\AuthClient');
    \Config::set('auth.table', 'clients');

    return $next($request);
}
</code></pre>

<p>ApiAuthController login function:</p>

<pre><code>public function authenticate(Request $request)
{
    $cred = $request-&gt;only('email', 'password', 'client_code' );

    $validator = $this-&gt;validator($cred);
    if($validator-&gt;fails()) {
        return response()-&gt;json($validator-&gt;errors());
    }

    $credentials = ['email'=&gt; $cred['email'], 'password'=&gt; $cred['password']];

    /*
     * If the user enters a "client_code", login the user with that credential
     */
    if(issetNotEmpty($cred['client_code'])) {
        \App\Models\AuthClient::$defaultAuth = 'client_code';
        $credentials = ['client_code' =&gt; $cred['client_code'], 'password' =&gt; $cred['client_code']];
    }

    try {
        if (!$token = JWTAuth::attempt($credentials)) {
            return response()-&gt;json(['error' =&gt; 'Datele de autentificare nu sunt corecte.'], 401);
        }
    } catch (JWTException $e) {
        // something went wrong
        return response()-&gt;json(['error' =&gt; 'could_not_create_token'], 500);
    }

    // if no errors are encountered we can return a JWT
    return response()-&gt;json(compact('token'));
}
</code></pre>

<p>My problem is when I try to retrieve the logged user from the token like this: </p>

<pre><code>public function getContracts(Request $request)
{
    $client = JWTAuth::parseToken()-&gt;authenticate();
    $contracts = $client-&gt;contracts;
    dd($client);

    return response()-&gt;json($contracts);
}
</code></pre>

<p>The <code>authenticate()</code> function returns a match model from the 'users' table instead of 'clients' although I have set the auth.php and jwt.php to 'Models\AuthClient' and the ID is from 'clients'.</p>

<p>AuthCient Model:</p>

<pre><code>    class AuthClient extends Model implements AuthenticatableContract, CanResetPasswordContract
{
    use Authenticatable, CanResetPassword;

    protected $table = 'clients';

    public static $defaultAuth = 'email';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [ 'email', 'login_password', 'api_token'];

    protected $hidden = ['login_password', 'api_token'];
}
</code></pre>

<p>What am I missing? </p>

<p>Thanks!</p>