# SettingsHub Custom Implementation with Singleton Pattern

## Overview

This implementation replaces the vendor `TomatoPHP\FilamentSettingsHub\Pages\SettingsHub` class with a custom `SettingsHubCustom` class that includes:

- Custom `navigationSort` property set to 1
- Singleton pattern implementation in Laravel 12
- Proper integration with Filament v4

## Files Created

### 1. SettingsHubCustom Page

**Location:** `Modules/Setting/app/Filament/Pages/SettingsHubCustom.php`

This class extends the vendor `SettingsHub` and adds:

- `protected static ?int $navigationSort = 1;` - Sets the navigation order
- Singleton pattern implementation with private constructor
- Prevention of cloning and unserializing
- `getInstance()` method for singleton access

### 2. SettingsHubService

**Location:** `Modules/Setting/app/Services/SettingsHubService.php`

A singleton service class that manages the SettingsHub configuration:

- Implements full singleton pattern (private constructor, **clone, **wakeup)
- Stores configuration data
- Provides methods to get/set navigation sort and other config values

### 3. CustomFilamentSettingsHubPlugin

**Location:** `Modules/Setting/app/Filament/Plugins/CustomFilamentSettingsHubPlugin.php`

Extends the vendor plugin to register our custom page:

- Overrides `register()` method to use `SettingsHubCustom` instead of vendor `SettingsHub`
- Maintains compatibility with SiteSettings and SocialMenuSettings

### 4. SettingsHub Facade

**Location:** `Modules/Setting/app/Facades/SettingsHub.php`

Provides static access to the singleton service:

- Easy access via `SettingsHub::getInstance()`
- Static methods for configuration management

## Updated Files

### 1. SettingServiceProvider

**Location:** `Modules/Setting/app/Providers/SettingServiceProvider.php`

Changes:

- Added import for `SettingsHubService`
- Registered `SettingsHubService` as a singleton in the container
- Registered alias `'settings.hub'` for facade access

### 2. AdminPanelProvider

**Location:** `app/Providers/Filament/AdminPanelProvider.php`

Changes:

- Added import for `CustomFilamentSettingsHubPlugin`
- Replaced `\TomatoPHP\FilamentSettingsHub\FilamentSettingsHubPlugin::make()` with `CustomFilamentSettingsHubPlugin::make()`

## How to Use

### Accessing the Singleton Service

```php
// Using the facade
use Modules\Setting\Facades\SettingsHub;

$navigationSort = SettingsHub::getNavigationSort();
SettingsHub::setNavigationSort(2);

// Or using the service container
$service = app(\Modules\Setting\Services\SettingsHubService::class);
$config = $service->getAllConfig();

// Or direct access to the singleton instance
$instance = \Modules\Setting\Services\SettingsHubService::getInstance();
```

### Accessing the Custom Page

The custom page is automatically registered through the plugin and will appear in your Filament admin panel with navigation sort order of 1.

## Benefits

1. **Singleton Pattern**: Ensures only one instance of the service exists throughout the application
2. **Custom Navigation Sort**: Settings Hub will appear first in navigation (sort = 1)
3. **Module Isolation**: All customizations are in the Setting module, not modifying vendor files
4. **Extendable**: Easy to add more customizations to the page or service
5. **Laravel 12 Compatible**: Uses modern Laravel 12 service container features
6. **Filament v4 Compatible**: Fully compatible with Filament v4 architecture

## Notes

- The singleton pattern is implemented at the service level (`SettingsHubService`)
- The page class (`SettingsHubCustom`) includes singleton methods but note that Filament may instantiate pages multiple times in its lifecycle
- The true singleton behavior is managed by Laravel's service container binding
- The facade provides convenient static access to the singleton service
