Skip to content

Latest commit

 

History

History
98 lines (70 loc) · 1.92 KB

index.md

File metadata and controls

98 lines (70 loc) · 1.92 KB

Filament Settings

Introduction

Installation

Installation is pretty easy. Just run the following command.

composer require codedor/filament-settings

Usage

Register settings

Add the following file Tab.php to the App/Settings folder.

<?php

namespace App\Settings;

use Codedor\FilamentSettings\Settings\SettingsInterface;

class Tab implements SettingsInterface
{
    // Optional title function, remove to generate automatically
    public static function title(): string
    {
        return 'Tab title';
    }

    public static function schema(): array
    {
        return [];
    }
}

and register the tab in the filament-settings.php file.

<?php

...
use App\Settings\Tab;

return [
    ...
    'tabs' => [
        Tab::class,
    ],
];

Defining settings

This package uses the Filament fields to enable easy form building. Just return the wanted fields with all it's options in the schema method.

use Filament\Forms\Components\TextInput;

public static function schema(): array
{
    return [
        TextInput::make('site.name')
            ->rules([
                ...
            ]),  
    ];
}

Validation

Required fields

To have a better user experience, it is highly recommended to use the Codedor\FilamentSettings\Rules\SettingsMustBeFilledIn validation rule instead of the default required rule.

This way, users are still able to save the settings when 'required' settings are not yet in possession. All rules that have the SettingsMustBeFilledIn attached will appear in the RequiredFields widget on the dashboard and settings page. This way, users will be reminded to fill in the required settings.

Sort tabs

The tabs will be sorted by first registered. To change this, add the following method to the Tab class. Tabs without this method will be sorted first, as default is 0.

public static function priority(): int
{
    return 1;
}