assetのパスについて
なぜか通常のようにassetが使えなかった。
tenancyを入れると標準でassetがtenancy用になっているらしい。
config/tenancy.php
ファイルの下記部分が影響しているとのこと。
'asset_helper_tenancy' => true,
から
'asset_helper_tenancy' => false,
に変更
ルーティングについて
非テナント(central-domain,non tenant)のルーティング(web.php)をいくらいじっても動かなかった。
いつの間にか要らないものを設定していたらしい。
kernel.php
のmiddlewereGrop
のwebを確認
// \App\Http\Middleware\InitializeTenancyByDomainWithCentralCheck::class,
// \Stancl\Tenancy\Middleware\PreventAccessFromCentralDomains::class,
RouteServiceProvider.php
にこれが書いてあるかも確認
public function boot(): void
{
何か書いてあるものは消さない
$this->routes(function () {
何か書いてあるものは消さない
$this->mapWebRoutes();<-追記
$this->mapApiRoutes();<-追記
});
}
protected function mapWebRoutes()
{
foreach ($this->centralDomains() as $domain) {
Route::middleware('web')
->domain($domain)
->namespace($this->namespace)
->group(base_path('routes/web.php'));
}
}
protected function mapApiRoutes()
{
foreach ($this->centralDomains() as $domain) {
Route::prefix('api')
->domain($domain)
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
}
}
protected function centralDomains(): array
{
return config('tenancy.central_domains', []);
}
リクエスト データ (ヘッダーまたはクエリ パラメータ) に基づいてテナントを識別する方法
これがドキュメント等が全くない
ルーティングファイルに下記を設定しておけば出来てそう(確証はない)
use Stancl\Tenancy\Middleware\InitializeTenancyByRequestData;
Route::middleware([
'api',
InitializeTenancyByRequestData::class,<-これ
])->group(function () {
Route::get('/', function () {
// dd(\App\Models\User::all());
return 'This is your multi-tenant application. The id of the current tenant is ' . tenant('id');
});
});
curl -H "X-Tenant: tenantsテーブルにある任意のid" http://自分のドメイン/api
これでちゃんと返っては来ていた