Framework: Order of Middleware Issue

Created on 12 Jun 2017  路  5Comments  路  Source: laravel/framework

In web.php I've switched Postgres schemas in middleware as the subdomain type of HTTP request is made. This way:

Route::group(
    [
        'domain'     => '{tenant}.' . config('app.url'),
        'middleware' => 'select-schema'
    ],
    function () {
        $this->get('/', 'HomeController@index')->middleware('auth');
    }
);

In select-schema middleware, I do something like this. This works correctly. (don't worry)

DB::select('SET search_path TO ' . {tenant});

My main problem is that: I've different migrations for public schema and for any individual tenant. In individual tenant I have users table. As soon I'm logged in it pop up this error.

SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "users" does not exist

The main issue is

$this->get('/', 'HomeController@index')->middleware('auth');

The model works well but middleware auth execute first before select-schema

How do I order? select-schema then auth

Most helpful comment

You can update the $middlewarePriority in your App\Kernel.

Check the original order in Illuminate\Foundation\Http\Kernel before you proceed.

All 5 comments

You can update the $middlewarePriority in your App\Kernel.

Check the original order in Illuminate\Foundation\Http\Kernel before you proceed.

I didn't know that even exists. Thank you so much.

I think this should be in the docs, it is very helpful

$middlewarePriority seems to be not used in laravel 5.5 . Do we have any other solutions here ?

@majuansari it works for me in 5.7 and 5.8

Was this page helpful?
0 / 5 - 0 ratings

Related issues

YannPl picture YannPl  路  3Comments

PhiloNL picture PhiloNL  路  3Comments

gabriellimo picture gabriellimo  路  3Comments

RomainSauvaire picture RomainSauvaire  路  3Comments

shopblocks picture shopblocks  路  3Comments