Laravel中间件顺序(中间件优先级).使用Postgres的多租户 [英] Laravel order of middleware (Middleware Priority). Multi-tenant using Postgres
问题描述
在 web.php 中,随着发出HTTP请求的子域类型,我已经在中间件中切换了Postgres模式.这样:
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');
}
);
在 select-schema 中间件中,我这样做.这可以正常工作. (不用担心)
In select-schema middleware, I do something like this. This works correctly. (don't worry)
DB::select('SET search_path TO ' . {tenant});
我的主要问题是:对于public
模式和任何individual tenant
,我都有不同的migrations
.在individual tenant
中,我有users
表.一旦我登录,就会弹出此错误.
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]:未定义表:7错误:关系用户"不存在
SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "users" does not exist
主要问题是
$this->get('/', 'HomeController@index')->middleware('auth');
模型运行良好,但是中间件auth
在select-schema
The model works well but middleware auth
execute first before select-schema
如何订购? select-schema
然后auth
推荐答案
我找到了解决方案,
为此,在App\Kernel
中有一个叫做$middlewarePriority
的东西.
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
这篇关于Laravel中间件顺序(中间件优先级).使用Postgres的多租户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!