Files
autocrm/app/Filament/Tenant/Resources/WorkOrderResource/Pages/CreateWorkOrder.php
T
Vasyka c2f87a468f fix: TenantManager scoped() + explicit company_id in WO create
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>
2026-09-06 10:49:18 +00:00

28 lines
903 B
PHP

<?php
namespace App\Filament\Tenant\Resources\WorkOrderResource\Pages;
use App\Filament\Tenant\Resources\WorkOrderResource;
use App\Models\Tenant\WorkOrder;
use App\Tenancy\TenantManager;
use Filament\Resources\Pages\CreateRecord;
class CreateWorkOrder extends CreateRecord
{
protected static string $resource = WorkOrderResource::class;
protected function mutateFormDataBeforeCreate(array $data): array
{
$companyId = app(TenantManager::class)->currentId();
$data['number'] = WorkOrder::generateNumber($companyId);
$data['company_id'] = $companyId; // explicit — prevents Octane singleton race condition
return $data;
}
/** After create, land on the dashboard (single hub) instead of the raw edit. */
protected function getRedirectUrl(): string
{
return url('/app/work-orders/' . $this->record->id . '/dashboard');
}
}