nalzai35/filament-settings

This is my package filament-settings

v1.0.1 2024-07-20 07:41 UTC

This package is auto-updated.

Last update: 2024-10-20 08:09:15 UTC


README

Latest Version on Packagist Total Downloads

This package adds a settings page in the filaments stored in your database.

Installation

You can install the package via composer:

composer require nalzai35/filament-settings

Add the plugin to your desired Filament panel:

use Nalzai35\FilamentSettings\FilamentSettingsPlugin;
 
class FilamentPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->plugins([
                FilamentSettingsPlugin::make()
            ]);
    }
}

You can publish and run the migrations with:

php artisan vendor:publish --tag="filament-settings-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="filament-settings-config"

This is the contents of the published config file:

return [
    'database_table_name' => 'settings',
    'cache_key' => 'settings'
];

Optionally, you can publish the views using

php artisan vendor:publish --tag="filament-settings-views"

Usage

Create a settings page at app/Filament/Pages/Settings/Settings.php:

namespace App\Filament\Pages\Settings;

use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Nalzai35\FilamentSettings\Pages\SettingsPage;

class Settings extends SettingsPage
{
    protected static ?string $navigationIcon = 'heroicon-o-cog-6-tooth';

    public function form(Form $form): Form
    {
        return $form
                ->schema([
                    Forms\Components\Tabs::make('settings')
                        ->schema([
                            Forms\Components\Tabs\Tab::make('General')
                                ->statePath('general')
                                ->schema([
                                    Forms\Components\TextInput::make('brand_name')
                                        ->required()
                                ]),
                            Forms\Components\Tabs\Tab::make('Seo Meta')
                                ->statePath('seo_meta')
                                ->schema([
                                    Forms\Components\Section::make('Home Page')
                                        ->statePath('home_page')
                                        ->collapsible()
                                        ->schema([
                                            Forms\Components\TextInput::make('title'),
                                            Forms\Components\Textarea::make('description')
                                        ])
                                ])
                        ]),
                ])
                ->columns(1);
    }
}

Retrieving settings

You can retrieve settings using the helper function setting(), like the config() function in Laravel:

setting('general.name');

// Retrieve a default value if the configuration value does not exist...
setting('general.name', 'Filament Settings');

// To set configuration values at runtime
setting(['general.timezone' => 'America/Chicago']);

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.