tomatophp/filament-settings-hub
Installation
composer require tomatophp/filament-settings-hub
Publish the package assets and config:
php artisan vendor:publish --provider="TomatoPHP\FilamentSettingsHub\FilamentSettingsHubServiceProvider" --tag="filament-settings-hub-config"
php artisan vendor:publish --provider="TomatoPHP\FilamentSettingsHub\FilamentSettingsHubServiceProvider" --tag="filament-settings-hub-migrations"
Run migrations:
php artisan migrate
Register the Plugin
Add to app/Providers/Filament/AdminPanelProvider.php:
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
\TomatoPHP\FilamentSettingsHub\FilamentSettingsHubPlugin::make(),
]);
}
First Use Case Define a setting group in a migration or via the GUI:
use TomatoPHP\FilamentSettingsHub\Database\SettingGroup;
SettingGroup::create([
'name' => 'App Configuration',
'slug' => 'app-config',
'description' => 'Global app settings',
]);
Access settings in code:
$value = \TomatoPHP\FilamentSettingsHub\Facades\SettingsHub::get('app-config.some_setting');
GUI-Driven Configuration
/settings-hub route.app-config, payment-gateway) and keys (e.g., max_upload_size, stripe_api_key).Dynamic Form Fields
Leverage the SettingField model to define custom fields for each setting key:
use TomatoPHP\FilamentSettingsHub\Database\SettingField;
SettingField::create([
'group_id' => 1, // app-config group
'key' => 'max_upload_size',
'label' => 'Max Upload Size (MB)',
'type' => 'number',
'default' => 10,
'validation_rules' => 'required|min:1',
]);
Accessing Settings
$value = SettingsHub::get('app-config.max_upload_size');
$this->app->bind(SettingsHub::class, function ($app) {
return new SettingsHub(config('filament-settings-hub'));
});
Environment-Based Fallbacks
Use the fallback config option to default to .env values:
// config/filament-settings-hub.php
'fallbacks' => [
'app-config.max_upload_size' => env('MAX_UPLOAD_SIZE', 10),
],
Caching Enable Redis caching for performance:
// config/filament-settings-hub.php
'cache' => [
'enabled' => true,
'driver' => 'redis',
'prefix' => 'settings_hub_',
],
public static function getFilamentSettingsHubAccess(): array
{
return ['admin']; // Only users with 'admin' role can access
}
use TomatoPHP\FilamentSettingsHub\Events\SettingUpdated;
SettingUpdated::listen(function (SettingUpdated $event) {
Log::info("Setting updated: {$event->key}", $event->payload);
});
Route::middleware('auth:sanctum')->get('/api/settings/{group}', function (string $group) {
return SettingsHub::getGroup($group);
});
Migration Conflicts
setting_groups or setting_fields tables, ensure they match the package’s schema:
Schema::create('setting_groups', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('slug')->unique();
$table->text('description')->nullable();
$table->timestamps();
});
Caching Stale Data
php artisan cache:clear
php artisan view:clear
SettingsHub::forget($key) to manually invalidate a single setting.Permission Denied
filament-settings-hub plugin is registered in the correct panel provider.resources and pages for the plugin route.Field Type Limitations
rich_text, color_picker) require additional setup:
// config/filament-settings-hub.php
'custom_field_types' => [
'rich_text' => \TomatoPHP\FilamentSettingsHub\FieldTypes\RichTextField::class,
],
Log Settings Enable debug mode in config:
'debug' => true,
Logs will appear in storage/logs/laravel.log.
Query Builder Inspect raw queries with Laravel Debugbar or Tinker:
php artisan tinker
>>> \TomatoPHP\FilamentSettingsHub\Database\Setting::query()->toSql();
Seeding Data
Use the SettingsHubSeeder for testing:
use TomatoPHP\FilamentSettingsHub\Database\SettingGroup;
use TomatoPHP\FilamentSettingsHub\Database\SettingField;
SettingGroup::create(['name' => 'Test', 'slug' => 'test']);
SettingField::create([
'group_id' => 1,
'key' => 'test_setting',
'type' => 'text',
'default' => 'default_value',
]);
Custom Field Types
Extend the SettingFieldType interface:
namespace App\FilamentSettingsHub;
use TomatoPHP\FilamentSettingsHub\Contracts\SettingFieldType;
class CustomFieldType implements SettingFieldType
{
public function getWidget(): string
{
return 'custom-widget';
}
public function getValidationRules(): array
{
return ['required'];
}
}
Register in config:
'custom_field_types' => [
'custom' => \App\FilamentSettingsHub\CustomFieldType::class,
],
Override Default Views Publish and modify the package’s views:
php artisan vendor:publish --provider="TomatoPHP\FilamentSettingsHub\FilamentSettingsHubServiceProvider" --tag="filament-settings-hub-views"
Edit files in resources/views/vendor/filament-settings-hub/.
API Resources Create a custom API resource for settings:
namespace App\Http\Resources;
use TomatoPHP\FilamentSettingsHub\Database\SettingGroup;
use Illuminate\Http\Resources\Json\JsonResource;
class SettingGroupResource extends JsonResource
{
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'fields' => $this->fields->map(fn ($field) => [
'key' => $field->key,
'value' => SettingsHub::get("{$this->slug}.{$field->key}"),
]),
];
}
}
Multi-Tenant Support
Scope settings by tenant using Laravel’s tenant() helper:
$tenantId = tenant('id');
$value = SettingsHub::where('tenant_id', $tenantId)->get('app-config.theme');
How can I help you explore Laravel packages today?