visanduma/nova-settings
Composer 安装命令:
composer require visanduma/nova-settings
包简介
Advance settings UI for Laravel Nova
README 文档
README
⚙ Nova Settings
Settings management UI for Laravel Nova™ dashboard using Native fields
💠 Install
composer require visanduma/nova-settings
💠 Configuration
Publish config & migrations
php artisan vendor:publish --tag=nova-settings
Run migration
php artisan migrate
Update config file (optional)
<?php return [ /* default path for load settings class */ 'settings_path' => app_path('Nova/Settings'), ];
Use trait in Model. generally in User.php
use Visanduma\NovaSettings\HasNovaSettings; class User extends Authenticatable { use HasNovaSettings; }
Register tool in Nova Service Provider
public function tools() { return [ /* other tools */ \Visanduma\NovaSettings\NovaSettings::make(), ]; }
💠 Create your first setting class
You can use nova-settings:make command to build a fresh settings class
php artisan nova-settings:make Contact
Adding fields is the same as in Nova Resource
class Contact extends NovaSettingsMum { public $icon = 'phone'; public function fields() { return [ Text::make('Name')->rules('required'), Text::make('Address')->rules('required'), Text::make('City')->rules('required'), Select::make('Province')->options([ 'NC' => 'North Central', 'N' => 'Northern', ]), Country::make('Country')->rules('required'), Panel::make('Home', [ Text::make('Contact name'), Text::make('Phone'), ])->help('Update you home contacts'), ]; } }
💠 Registering settings
All settings class in the default path are automatically registered. If you are going to use a different path, please configure it in nova-settings.php
If you want to register settings class manually, use NovaSettings::register method in the service provider
namespace App\Nova\Settings; public function boot() { NovaSettings::register([ Contact::class, ]); }
💠 Customizing the settings class
You can customize settings class as per your needs
Customizing settings menu icon. you can use any Heroicons
public $icon = 'bell';
Customizing section label
public function label():string { return 'User contacts'; }
Customizing uriKey. uriKey is used when saving/retrieving the settings
public function uriKey(): string { return 'user-contacts'; }
💠 Model settings vs Global settings
There are two type of settings. Model settings & Global Settings. Model settings is always bound to an entity (Auth user by default) while global settings are not bound to any entity
You can easily configure the settings type with global property in the settings class
protected bool $global = false;
if you want use another Model rather than User Model , just override the getModel() method on settings class
protected function getModel() { return Auth::user(); // default model is Auth User }
💠 Retrieving the settings
use Visanduma\NovaSettings\NovaSettings; // getting single value NovaSettings::get('contact.name', 'default value'); nova_settings('contact.name','default value'); // getting whole settings array NovaSettings::get('contact'); nova_settings('contact'); // use different Model instead Auth User NovaSettings::get('contact.name', 'default value', Admin::find(3)); nova_settings('contact.name','default value', Admin::find(3)); // getting global settings NovaSettings::global('system.email'); NovaSettings::global('system'); nova_settings_global('system.phone'),
💠 Transforming inputs
If you need to customize user-submitted form data, override the following method in the settings class. This method will receive form data array as its argument
protected function transformInputs(array $inputs): array { // do your modifications return $inputs; }
💠 Hooks
protected function afterSaved(NovaRequest $request) { // this method will be called after the form is saved }
Known issues
- File inputs does not work correctly
- Uploaded files cannot be delete
- Not works well with 3rd party fields
Todo
- Authorization
- Caching
- Events
Credits
License
The MIT License (MIT). Please see License File for more information.
visanduma/nova-settings 适用场景与选型建议
visanduma/nova-settings 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 36 次下载、GitHub Stars 达 9, 最近一次更新时间为 2024 年 06 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「configuration」 「nova」 「laravel」 「Settings」 「preference」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 visanduma/nova-settings 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 visanduma/nova-settings 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 visanduma/nova-settings 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova card that shows you your system information.
A Laravel Nova card.
Configuration component
A Laravel Nova package for publishable fields
A Laravel Nova package for translatable fields
A Laravel Nova Image field. you can paste or drag or chose an image
统计信息
- 总下载量: 36
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-06-13
