\Filament\Resources\Pages\ListRecords::route('/'), 'create' => CreateClient::route('/create'), 'edit' => EditClient::route('/{record}/edit'), ]; } public static function canViewAny(): bool { return auth()->user()?->super_admin ?? false; } public static function isScopedToTenant(): bool { return false; } public static function form(Form $form, $client = null): Form { return $form->schema([ // The form schema for the Client resource TextInput::make('name') ->rules([ 'required', Rule::unique('clients', 'name')->ignore($client->id ?? null), ]) ->label('Client Name') ->default($client ? $client->name : null) ->afterStateUpdated(function ($state, callable $set) { $set('handle', Client::generateUniqueHandle($state)); }), TextInput::make('dba') ->rules([ Rule::unique('clients', 'dba')->ignore($client->id ?? null), ]) ->label('DBA') ->default($client ? $client->dba : null), TextInput::make('billing_address') ->required() ->label('Billing Address') ->default($client ? $client->billing_address : null), TextInput::make('phone_number') ->label('Phone Number') ->tel() ->required() ->rules([ 'required', 'phone:US,MX,CA', Rule::unique('clients', 'phone_number')->ignore($client->id ?? null), ]) ->afterStateUpdated(function ($state, callable $set) { if ($state) { $set('phone_number', phone($state, ['US', 'MX', 'CA'])->formatE164()); } }), // Other fields... ]); } protected function mutateFormDataBeforeCreate(array $data): array { $data['handle'] = Client::generateUniqueHandle($data['name']); return $data; } protected function mutateFormDataBeforeSave(array $data): array { $data['handle'] = Client::generateUniqueHandle($data['name'], $data['id'] ?? null); return $data; } public static function table(Table $table): Table { return $table ->columns([ ImageColumn::make('logo_path') ->label('Logo') ->disk('public') ->width(25) ->height(25), TextColumn::make('name') ->label('Client Name') ->getStateUsing(fn($record) => $record->display_name) ->searchable(['display_name']), TextColumn::make('billing_address') ->label('Billing Address') ->searchable(), TextColumn::make('proxy_phone') ->label('Proxy Phone') ->searchable(), ]) ->filters([ Tables\Filters\TrashedFilter::make(), ]) ->actions([ EditAction::make(), DeleteAction::make(), Action::make('assign_proxy_phone') ->label('Assign Proxy Phone') ->modal(fn () => Modal::make() ->schema([ TextInput::make('area_code') ->label('Area Code') ->numeric() ->required(), ]) ->submitAction(fn () => SubmitAction::make('Assign')) ->onSubmit(function (callable $livewire, $formData) { $client = $livewire->record; $proxyPhoneService = app(ProxyPhoneService::class); try { $proxyPhoneService->assignProxyPhone($client, $formData['area_code']); Notification::make() ->title('Success') ->body('Proxy phone assigned successfully') ->success() ->send(); } catch (\Exception $e) { Notification::make() ->title('Error') ->body($e->getMessage()) ->danger() ->send(); } })) ->hidden(fn($livewire) => isset($livewire->record) ? $livewire->record->hasProxyPhone() : false), Action::make('update_proxy_configuration') ->label('Update Proxy Configuration') ->modal(fn () => Modal::make() ->schema([ TextInput::make('route_to') ->label('Route To') ->required() ->tel() ->mask('(999) 999-9999'), ]) ->submitAction(fn () => SubmitAction::make('Update')) ->onSubmit(function (callable $livewire, $formData) { $client = $livewire->record; $proxyPhoneService = app(ProxyPhoneService::class); $proxyPhoneNumber = $client->clientPhoneNumbers()->where('type', 'proxy')->first(); if ($proxyPhoneNumber) { $proxyPhoneService->updateProxyPhoneConfiguration($proxyPhoneNumber, $formData['route_to']); Notification::make() ->title('Success') ->body('Proxy phone configuration updated successfully') ->success() ->send(); } else { Notification::make() ->title('Error') ->body('No proxy phone found for this client') ->danger() ->send(); } })) ->hidden(fn ($livewire) => !$livewire->record->hasProxyPhone()), ]) ->bulkActions([ Tables\Actions\BulkActionGroup::make([ Tables\Actions\DeleteBulkAction::make(), ]), ]); } public static function getRelations(): array { return [ UserRelationManager::class, ClientContactRelationManager::class, SubscriptionRelationManager::class, ]; } public static function getNavigation(): array { return [ NavigationItem::make('Clients') ->url(static::getUrl()) ->icon(static::$navigationIcon) ->group(static::$navigationGroup) ->groupIcon(static::$navigationGroupIcon) ->groupSort(static::$navigationGroupSort) ->sort(1000) ->visible(auth()->user()?->super_admin ?? false), ]; } public static function infolist(Infolist $infolist): Infolist { return $infolist ->schema([ ImageEntry::make('logo_path') ->label('Client Logo') ->disk('public') ->width(150) ->height(150) ->visible(fn($record) => !empty($record->logo_path)), ]); } public static function getSlug(): string { return 'clients'; } }