$data * @return array */ protected function mutateFormDataBeforeCreate(array $data): array { $workspaceId = app(WorkspaceContext::class)->currentWorkspaceId(); if ($workspaceId !== null) { $data['workspace_id'] = $workspaceId; } return $data; } protected function afterCreate(): void { $user = auth()->user(); if (! $user instanceof User) { return; } $user->tenants()->syncWithoutDetaching([ $this->record->getKey() => ['role' => 'owner'], ]); } }