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