filamentphp / spatie-laravel-settings-plugin by DanHarrin

Filament support for `spatie/laravel-settings`.
769,058
59
4
Package Data
Maintainer Username: DanHarrin
Package Create Date: 2021-11-25
Package Last Update: 2024-11-13
Home Page: https://github.com/filamentphp/filament
Language: PHP
License: MIT
Last Refreshed: 2024-11-19 03:04:12
Package Statistics
Total Downloads: 769,058
Monthly Downloads: 53,555
Daily Downloads: 2,209
Total Stars: 59
Total Watchers: 4
Total Forks: 8
Total Open Issues: 0

Filament Spatie Settings Plugin

Installation

Install the plugin with Composer:

composer require filament/spatie-laravel-settings-plugin:"^3.0-stable" -W

Preparing your page class

Settings pages are Filament pages that extend the Filament\Pages\SettingsPage class.

This package uses the spatie/laravel-settings package to store and retrieve settings via the database.

Before you start, create a settings class in your app/Settings directory, and a database migration for it. You can find out more about how to do this in the Spatie documentation.

Once you've created your settings class, you can create a settings page in Filament for it using the following command:

php artisan make:filament-settings-page ManageFooter FooterSettings

In this example, you have a FooterSettings class in your app/Settings directory.

In your new settings page class, generated in the app/Filament/Pages directory, you will see the static $settings property assigned to the settings class:

protected static string $settings = FooterSettings::class;

Building a form

You must define a form schema to interact with your settings class inside the form() method.

Since the Form Builder is installed in the Panel Builder by default, you may use any form fields or layout components you like:

use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;

public function form(Form $form): Form
{
    return $form
        ->schema([
            TextInput::make('copyright')
                ->label('Copyright notice')
                ->required(),
            Repeater::make('links')
                ->schema([
                    TextInput::make('label')->required(),
                    TextInput::make('url')
                        ->url()
                        ->required(),
                ]),
        ]);
}

The name of each form field must correspond with the name of the property on your settings class.

The form will automatically be filled with settings from the database, and saved without any extra work.

Publishing translations

If you wish to translate the package, you may publish the language files using:

php artisan vendor:publish --tag=filament-spatie-laravel-settings-plugin-translations