Apply Middleware to all routes except `setup/*` in Laravel 5.4 : <p>I'm experimenting with Middleware in my Laravel application. I currently have it set up to run on every route for an authenticated user, however, I want it to ignore any requests that begin with the <code>setup</code> URI.</p>

<p>Here is what my <code>CheckOnboarding</code> middleware method looks like:</p>

<pre><code>public function handle($request, Closure $next)
{
    /** 
    * Check to see if the user has completed the onboarding, if not redirect.
    * Also checks that the requested URI isn't the setup route to ensure there isn't a redirect loop.
    */
    if ($request-&gt;user()-&gt;onboarding_complete == false &amp;&amp; $request-&gt;path() != 'setup') {
        return redirect('setup');
    } else {
        return $next($request);
    }
}
</code></pre>

<p>This is being used in my routes like this:</p>

<pre><code>Route::group(['middleware' =&gt; ['auth','checkOnboarding']], function () {
    Route::get('/home', 'HomeController@index');
    Route::get('/account', 'AccountController@index');

    Route::group(['prefix' =&gt; 'setup'], function () {
        Route::get('/', 'OnboardingController@index')-&gt;name('setup');
        Route::post('/settings', 'SettingsController@store');
    }); 
});
</code></pre>

<p>Now, if I go to <code>/home</code> or <code>/account</code> I get redirected to <code>/setup</code> as you would expect. This originally caused a redirect loop error hence why <code>&amp; $request-&gt;path() != 'setup'</code> is in the Middleware.</p>

<p>I feel like this is a really clunky way of doing it, and obviously doesn't match anything after <code>setup</code> like the <code>setup/settings</code> route I have created.</p>

<p>Is there a better way to have this Middleware run on all routes for a user, but also set certain routes that should be exempt from this check? </p>
