cwsps154/filament-app-settings

保存应用设置的包

dev-main 2024-09-13 12:20 UTC

This package is auto-updated.

Last update: 2024-09-13 12:20:42 UTC


README

此包将帮助您构建具有自定义表单的设置面板,支持所有 Filament 表单组件。

安装

使用 Composer 安装

composer require cwsps154/filament-app-settings

运行

php artisan filament-app-settings:install

使用示例

将此代码添加到您的 Filament PannelProvider 类的 panel() 方法中

$panel->plugins([FilamentAppSettingsPlugin::make()]);

您将获得一些自定义选项

FilamentAppSettingsPlugin::make()->canAccess(function () {
                        return true;
                    })->appAdditionalField([])

在此处,使用 canAccess() 方法,您可以阻止对页面的查看和编辑访问,使用 appAdditionalField() 方法,您可以向默认应用标签添加额外的部分,这些部分将在您安装此插件后可用。

您可以通过运行此命令来发布配置文件 filament-app-settings.php

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

其中包含以下设置

return [
    'layout' => null,
    'cluster' => null,
    'navigation' => [
        'title' => 'filament-app-settings::app-settings.app.settings.title',
        'group' => 'filament-app-settings::app-settings.system',
        'label' => 'filament-app-settings::app-settings.app.settings',
        'icon' => 'heroicon-o-cog-8-tooth',
        'sort' => 100,
    ]
];

您可以使用 php artisan make:app-settings-tab Custom 命令创建一个自定义标签到此设置,该命令将在 app/Filament/Settings/Forms 文件夹内创建一个类。

<?php

namespace App\Filament\Settings\Forms;

use Filament\Forms\Components\Tabs\Tab;

class Custom
{
    /**
     * @return Tab
     */
    public static function getTab(): Tab
    {
        return Tab::make('custom')
                    ->label(__('Custom'))
                    ->icon('heroicon-o-computer-desktop')
                    ->schema(self::getFields())
                    ->columns()
                    ->statePath('custom');
    }

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

您可以使用 getTab() 自定义标签部分。请注意,您应该为标签提供唯一的名称,即 statePath。因为我们使用自定义辅助函数 get_settings() 来获取设置数据。因此,这些名称应该是唯一的。

get_settings() 接受 'tab_name.field_name'。

示例:get_settings('app.app_logo')。这将支持嵌套字段,如 Repeater,您可以通过点访问这些值。

getFields() 返回 Filament 表单组件的数组。您可以使用所有可用的表单组件。

截图

App Screenshot

感谢

实际上,我在使用了一个已经存在的 Filament 插件之后构建了这个包,该插件名为 Filament General Settings。我发现该包存在一些限制,因此我创建了此版本。感谢