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
I've found the solution,
For this, there's something called $middlewarePriority in App\Kernel.
Adding this help me solve the problem.
/**
* Responsible for prioritizing the middleware
*
* @var array
*/
protected $middlewarePriority = [
\App\Http\Middleware\SwitchSchema::class,
];
I've got solution from this link.
https://github.com/laravel/framework/issues/19565
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With