stepanenko3/nova-settings
Composer 安装命令:
composer require stepanenko3/nova-settings
包简介
This Laravel Nova settings tool based on env, using nativ nova fields and resources
README 文档
README
Description
This Laravel Nova settings tool based on env, using nativ nova fields and resources
Features
- Using native Nova resources
- Fully responsive
- Dark mode support
- Support all packages. Like nova-tabs, activity-log, etc.
- Different settings depending on the current Env
- Separation of settings into different classes
- Customizable model and resource
Requirements
php: >=8.0laravel/nova: ^4.0
Installation
# Install the package
composer require stepanenko3/nova-settings
Publish the config file:
php artisan vendor:publish --provider="Stepanenko3\NovaSettings\ToolServiceProvider" --tag="config"
Publish the migration file:
php artisan vendor:publish --provider="Stepanenko3\NovaSettings\ToolServiceProvider" --tag="migrations"
And run php artisan migrate
Next up, you must register the tool with Nova. This is typically done in the tools method of the NovaServiceProvider.
// in app/Providers/NovaServiceProvder.php // ... public function tools() { return [ // ... new \Stepanenko3\NovaSettings\NovaSettingsTool(), ]; }
Create your own configuration classes in app/Nova/Settings
// in app/Nova/Settings/Demo.php <?php namespace App\Nova\Settings; use Laravel\Nova\Fields\Boolean; use Stepanenko3\NovaSettings\Types\AbstractType; class Demo extends AbstractType { public function fields(): array { return [ Boolean::make('Param 1', 'param_1'), Boolean::make('Param 2', 'param_2'), Boolean::make('Param 3', 'param_3'), ]; } }
With Tabs
If you want to use eminiarts/nova-tabs
composer require eminiarts/nova-tabs
// in app/Nova/Settings/Demo.php <?php namespace App\Nova\Settings; use Eminiarts\Tabs\Tab; use Eminiarts\Tabs\Tabs; use Laravel\Nova\Fields\Boolean; use Stepanenko3\NovaSettings\Types\AbstractType; class Demo extends AbstractType { public function fields(): array { return [ Boolean::make('Param 1', 'param_1'), Boolean::make('Param 2', 'param_2'), Boolean::make('Param 3', 'param_3'), new Tabs('Tabs 1', [ new Tab('Tab 1', [ Boolean::make('Param 1', 'param_1'), Boolean::make('Param 2', 'param_2'), Boolean::make('Param 3', 'param_3'), ]), new Tab('Tab 2', [ Boolean::make('Param 1', 'param_1'), Boolean::make('Param 2', 'param_2'), Boolean::make('Param 3', 'param_3'), ]), new Tab('Tab 3', [ Boolean::make('Param 1', 'param_1'), Boolean::make('Param 2', 'param_2'), Boolean::make('Param 3', 'param_3'), ]), ]), ]; } }
Delcare your settings class in config/nova-settings.php
<?php return [ 'model' => \Stepanenko3\NovaSettings\Models\Settings::class, 'resource' => \Stepanenko3\NovaSettings\Resources\Settings::class, 'types' => [ \App\Nova\Settings\Demo::class, // Add this line ], ];
Usage
Click on the "Settings" menu item in your Nova app to see the tool.
Use helper function for access the settings
// settings(string|null $section, string|null $key = null, string|null $default = null, string|null $env = null) settings('demo', 'key', 'defaultValue', config('app.env'))
Get cart_link value from General settings in current Env
settings('general', 'cart_link')
Get all General settings
settings('general')
Get cart_link value from General settings in specific Env with default value
settings( section: 'general', key: 'cart_link', default: true, env: 'production' ); // OR settings('general', 'cart_link', true, 'production');
Configuration
All the configuration is managed from a single configuration file located in config/nova-settings.php
Extends default model
Create your own model that will extends \Stepanenko3\NovaSettings\Models\Settings
// in app/Models/Settings.php <?php namespace App\Models; use Spatie\Activitylog\LogOptions; use Spatie\Activitylog\Traits\LogsActivity; class Settings extends \Stepanenko3\NovaSettings\Models\Settings { use LogsActivity; public function getActivitylogOptions(): LogOptions { return LogOptions::defaults() ->logFillable() ->logOnlyDirty(); } }
Declare your model 'model' => \App\Models\Settings::class, in config/nova-settings.php
Extends default Nova resource
Create your own resource that will extends \Stepanenko3\NovaSettings\Resources\Settings
// in app/Nova/Settings.php <?php namespace App\Nova; use Illuminate\Http\Request; use Laravel\Nova\Fields\HasMany; class Settings extends \Stepanenko3\NovaSettings\Resources\Settings { public function fields(Request $request) { return array_merge(parent::fields($request), [ HasMany::make('Activities', 'activities', 'App\Nova\ActivityLog'), ]); } }
Declare your resource 'resource' => \App\Nova\Settings::class, in config/nova-settings.php
Don't forget to create App\Nova\ActivityLog
Using dependsOn with out package
Use the settings-> prefix in the attribute parameter of the dependsOn method.
It is also necessary to get data from FormData with settings-> prefix
Select::make('Purchase Type', 'type') ->options([ 'personal' => 'Personal', 'gift' => 'Gift', ]), Text::make('Recipient') ->readonly() ->dependsOn( ['settings->type'], function (Text $field, NovaRequest $request, FormData $formData) { if ($formData->{'settings->type'} === 'gift') { $field->readonly(false)->rules(['required', 'email']); } } ),
Screenshots
Credits
Contributing
Thank you for considering contributing to this package! Please create a pull request with your contributions with detailed explanation of the changes you are proposing.
License
This package is open-sourced software licensed under the MIT license.
stepanenko3/nova-settings 适用场景与选型建议
stepanenko3/nova-settings 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21.17k 次下载、GitHub Stars 达 32, 最近一次更新时间为 2022 年 05 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「nova」 「laravel」 「Settings」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 stepanenko3/nova-settings 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 stepanenko3/nova-settings 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 stepanenko3/nova-settings 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova card that shows you your system information.
Persistent settings package for Laravel framework.
A Laravel Nova card.
A Zend Framework module to quickly and easily set PHP settings.
A Laravel Nova package for publishable fields
A Laravel Nova package for translatable fields
统计信息
- 总下载量: 21.17k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 32
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-05-10

