Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

isaackearl's avatar

@francis.rod01

What version of JWTAuth and Laravel are you using? This thread and the examples I wrote up are from some time ago.

You might try and make sure that your User model has the AuthenticatableContract and uses the Authenticatable trait. That adds a getAuthIdentifierName() method to the user Model.

Maybe I can help if I know what versions you are on.

Also, that middleware I was using I don't use anymore. I'm on the latest dev branch of JWTAuth now and my middleware looks more like this:

   /**
     * Handle an incoming request.
     *
     * @param  Request $request
     * @param  \Closure $next
     *
     * @throws \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
     *
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $this->authenticate($request);

        return $next($request);
    }

    /**
     * Attempt to authenticate a user via the token in the request.
     *
     * @param  Request $request
     *
     * @throws \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
     *
     * @return void
     */
    public function authenticate(Request $request)
    {
        $this->checkForToken($request);
        $this->auth->parseToken()->authenticate();
    }

the "checkForToken" method that I'm referencing is part of the BaseMiddleware class for JWTAuth.

Previous

Please or to participate in this conversation.