postare / db-config
此插件简化了 Filament 项目的配置管理,使动态配置页面的创建和管理变得简单。
3.02
2024-03-13 11:54 UTC
Requires
- php: ^8.2
- filament/filament: ^3.2
- illuminate/contracts: *
- spatie/laravel-package-tools: ^1.15.0
Requires (Dev)
- laravel/pint: ^1.14
- nunomaduro/collision: ^8
- orchestra/testbench: ^9.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- spatie/laravel-ray: ^1.35
README
此插件简化了 Filament 项目的配置管理,使动态配置页面的创建和管理变得简单。它提供以下功能:
它包括一个简单的命令来生成新的配置页面,以及一个灵活的表单模式来添加所需字段。该包负责将数据保存到数据库,并在需要时检索它。
此版本已在 Laravel 10.x 和 Filament 3.x 上进行测试。我们期待您的反馈和未来改进的建议。
在 Laravel 10.x 和 Filament 3.x 上测试
安装
通过 Composer 安装包
Laravel 10
composer require postare/db-config:^2.0
Laravel 11
composer require postare/db-config
发布并运行迁移
php artisan vendor:publish --tag="db-config-migrations"
php artisan migrate
用法
使用以下命令以及页面的名称创建配置页面
php artisan make:db_config website
# or specify panel
php artisan make:db_config website panelname
这将创建一个 Filament 页面和相应的视图。接下来,修改页面文件以添加您希望在配置页面上显示的字段。
示例
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'); } }
无需进行其他操作。该包负责将数据保存到数据库并在需要时检索它。
访问已保存的配置
您可以通过以下方式访问配置
// *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');
许可证
此软件包是开源软件,根据 MIT 许可证许可。
