Run Middleware Before Controller's Constructor On Laravel 5.1?
<p>I have a middleware that authenticates a JWT user using <a href="https://github.com/tymondesigns/jwt-auth" rel="noreferrer">tymon/jwt-auth</a> package:</p>

<pre><code>public function handle($request, \Closure $next)
{
    if (! $token = $this-&gt;auth-&gt;setRequest($request)-&gt;getToken()) {
        return $this-&gt;respond('tymon.jwt.absent', 'token_not_provided', 400);
    }

    try {
        $user = $this-&gt;auth-&gt;authenticate($token);
    } catch (TokenExpiredException $e) {
        return $this-&gt;respond('tymon.jwt.expired', 'token_expired', $e-&gt;getStatusCode(), [$e]);
    } catch (JWTException $e) {
        return $this-&gt;respond('tymon.jwt.invalid', 'token_invalid', $e-&gt;getStatusCode(), [$e]);
    }

    if (! $user) {
        return $this-&gt;respond('tymon.jwt.user_not_found', 'user_not_found', 404);
    }

    $this-&gt;events-&gt;fire('tymon.jwt.valid', $user);

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

<p>Then I have a controller and I want to pass the user from the middleware to the controller.</p>

<p>So I did on the controller:</p>

<pre><code>public function __construct()
{
    $this-&gt;user = \Auth::user();
}
</code></pre>

<p>The problem is that <code>$this-&gt;user</code> is <code>null</code>, but when I do this on a method of the controller, it's not null.</p>

<p>So:</p>

<pre><code>public function __construct()
{
    $this-&gt;user = \Auth::user();
}

public function index()
{
    var_dump($this-&gt;user); // null
    var_dump(\Auth::user()); // OK, not null
}
</code></pre>

<p>So the issue is that <code>__construct</code> is running before the middleware. How can I change that, or do you have another solution?</p>

<p>Update: I'm using <a href="https://github.com/dingo/api" rel="noreferrer">dingo/api</a> for routing, maybe it's an error on their side?</p>