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

3.02 2024-03-13 11:54 UTC

This package is auto-updated.

Last update: 2024-12-22 10:45:45 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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.

Screenshot

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.