c2f87a468f
FrankenPHP/Octane reuses the same PHP process for concurrent requests. TenantManager registered as singleton() was shared between requests — a concurrent request from another tenant could overwrite the current tenant context mid-flight, causing records to be saved with the wrong company_id. Fix 1: Change singleton() to scoped() so Octane flushes TenantManager at the end of each request (fresh instance per request lifecycle). Fix 2: Explicitly set company_id in mutateFormDataBeforeCreate() as an extra guard — even if the creating event fires in the wrong context, the value from the request's own TenantManager call takes precedence. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
44 lines
1.7 KiB
PHP
44 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Tenancy\TenantManager;
|
|
use Illuminate\Support\Facades\URL;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
public function register(): void
|
|
{
|
|
// scoped() instead of singleton() so Octane/FrankenPHP flushes the
|
|
// TenantManager between requests, preventing cross-request contamination
|
|
// where a concurrent request's tenant overwrites another request's context.
|
|
$this->app->scoped(TenantManager::class);
|
|
}
|
|
|
|
public function boot(): void
|
|
{
|
|
// Behind a TLS-terminating proxy (Cloudflare → Coolify Traefik → Octane).
|
|
// Force https on URL generation, but DON'T force root URL — each tenant
|
|
// subdomain must keep its own host so Livewire/CSRF work per-tenant.
|
|
if (! $this->app->runningInConsole() && (str_starts_with(config('app.url'), 'https://') || env('FORCE_HTTPS'))) {
|
|
URL::forceScheme('https');
|
|
}
|
|
|
|
// Auto-translate labels on every Filament component that has one.
|
|
// Without this, auto-derived labels (e.g. `name` → "Name") bypass __()
|
|
// and always render in English regardless of the app locale.
|
|
foreach ([
|
|
\Filament\Tables\Columns\Column::class,
|
|
\Filament\Tables\Filters\BaseFilter::class,
|
|
\Filament\Forms\Components\Field::class,
|
|
\Filament\Actions\Action::class,
|
|
\Filament\Actions\BulkAction::class,
|
|
] as $class) {
|
|
if (class_exists($class) && method_exists($class, 'configureUsing')) {
|
|
$class::configureUsing(fn ($c) => method_exists($c, 'translateLabel') ? $c->translateLabel() : $c);
|
|
}
|
|
}
|
|
}
|
|
}
|