postare / db-config
This plugin simplifies configuration management in Filament projects, enabling the easy creation and management of dynamic configuration pages.
Fund package maintenance!
postare
Requires
- php: ^8.2
- filament/filament: ^3.2
- illuminate/contracts: *
- spatie/laravel-package-tools: ^1.15.0
Requires (Dev)
- laravel/pint: ^1.14
- nunomaduro/collision: ^8
- orchestra/testbench: ^9.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- spatie/laravel-ray: ^1.35
README
This plugin simplifies configuration management in Filament projects, enabling the easy creation and management of dynamic configuration pages. It offers:
It includes a simple command to generate a new configuration page, and a flexible form schema to add the desired fields. The package handles saving data to the database and retrieving it as needed.
This version has been tested on Laravel 10.x and Filament 3.x. We look forward to your feedback and suggestions for future improvements.
Tested on Laravel 10.x and Filament 3.x
Installation
Install the package via Composer:
Laravel 10
composer require postare/db-config:^2.0
Laravel 11
composer require postare/db-config
Publish and run the migrations:
php artisan vendor:publish --tag="db-config-migrations"
php artisan migrate
Usage
Create a configuration page using the following command along with the name of the page:
php artisan make:db_config website
# or specify panel
php artisan make:db_config website panelname
This will create a Filament Page and a corresponding view. Next, modify the page file to add the fields you wish to display on the configuration page.
Example:
namespace App\Filament\Pages; use Filament\Forms\Form; use Postare\DbConfig\AbstractPageSettings; use Filament\Forms\Components\TextInput; class WebsiteSettingsPage extends AbstractPageSettings { public ?array $data = []; protected static ?string $title = 'Website Settings'; protected static ?string $navigationIcon = 'heroicon-o-globe-europe-africa'; protected ?string $subheading = 'Manage your website configurations here.'; protected static string $view = 'filament.config-pages.website'; protected function settingName(): string { return 'website'; } public function form(Form $form): Form { return $form ->schema([ TextInput::make('site_name')->required(), // Add more fields here ]) ->statePath('data'); } }
No additional steps are required. The package handles saving data to the database and retrieving it as needed.
Accessing Saved Configurations
You can access the configurations in the following ways:
// *Recommended* Helper method with optional default value db_config('website.site_name', 'default value') // Blade Directive @db_config('website.site_name') // Static Class \Postare\DbConfig\DbConfig::get('website.site_name', 'default value');
License
This package is open-sourced software licensed under the MIT License.