nhwin/settings
最新稳定版本:v1.0.1
Composer 安装命令:
composer require nhwin/settings
包简介
A Filament plugin for database-backed application settings and editable content, with caching and easy page generation.
README 文档
README
Requirements
- PHP version supported by your Laravel installation
- Laravel 12
- A database engine with JSON support (MySQL 5.7+, MariaDB 10.2.7+, PostgreSQL, SQLite recent versions)
- Filament 4
- PHP ^8.2
Installation
-
Install the package via Composer:
composer require nhwin/settings
-
Publish the assets (Configuration and Migration):
<!-- Publish Configuration --> php artisan vendor:publish --tag=settings-config <!-- Publish Migrations --> php artisan vendor:publish --tag=settings-migrations <!-- Publish Lang --> php artisan vendor:publish --tag=settings-translations <!-- or --> php artisan vendor:publish --provider="Nhwin\Settings\Providers\SettingServiceProvider"
-
Run the migration:
php artisan migrate
This command executes the migration file that you just published, creating the
settingstable (or the custom table name you defined in the config file) in your database. Your package is now ready to use!
Tip
If you want to use a custom table name instead of settings, edit the configuration file config/settings.php before running the migration. See the Configuration section for details.
🚀 Getting Started
Get up and running in just a few steps:
-
Generate Your First Settings Page
php artisan make:settings Website
This command creates a new Filament page (e.g., App/Filament/Pages/WebsiteSettings.php). You can repeat this step for more pages as needed.
Note
The generator will automatically add the “Settings” suffix to the page name for consistency (e.g., WebsiteSettings), but you can use any group name you wish.
-
Define Your Fields
Open the generated page and customize the form() method with your desired fields:
public function form(Form $form): Form { return $form ->components([ TextInput::make('site_name')->label('Site Name'), TextInput::make('contact_email')->label('Contact Email'), Toggle::make('maintenance_mode')->label('Maintenance Mode'), ]) ->statePath('data'); }
Note
You may use any Filament form fields or layout components - including third-party ones - to build your settings and content pages, giving you full flexibility in how data is structured and edited.
-
Save and Edit Settings from the Admin Panel
You can now edit these settings directly in your Filament admin panel—no extra boilerplate needed.
-
Use Your Settings Anywhere
Retrieve your configuration values easily:
-
In PHP:
$siteName = settings('website.site_name', 'Default Site Name');
-
In Blade:
<h1>{{ settings('website.site_name', 'Default Site Name') }}</h1> <!-- or --> <h1>@settings('website.site_name', 'Default Site Name')</h1>
-
That’s it! 🎉
Define your fields, save from the admin panel, and access your settings anywhere in your Laravel app.
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-29