42 lines
977 B
PHP
42 lines
977 B
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\TenantResource\Pages;
|
|
|
|
use App\Filament\Resources\TenantResource;
|
|
use App\Models\User;
|
|
use App\Support\Workspaces\WorkspaceContext;
|
|
use Filament\Resources\Pages\CreateRecord;
|
|
|
|
class CreateTenant extends CreateRecord
|
|
{
|
|
protected static string $resource = TenantResource::class;
|
|
|
|
/**
|
|
* @param array<string, mixed> $data
|
|
* @return array<string, mixed>
|
|
*/
|
|
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'],
|
|
]);
|
|
}
|
|
}
|