illuminatech/nova-config 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

illuminatech/nova-config

Composer 安装命令:

composer require illuminatech/nova-config

包简介

A Laravel Nova tool for application configuration management.

README 文档

README

A Laravel Nova tool for application configuration management


This extension provides Laravel Nova web interface for the application configuration setup.

For license information check the LICENSE-file.

Latest Stable Version Total Downloads

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist illuminatech/nova-config

or add

"illuminatech/nova-config": "*"

to the require section of your composer.json.

Usage

This extension provides Laravel Nova web interface for the application configuration setup. It provides a single form for the configuration parameters setup and restore defaults feature.

This extension relies on illuminatech/config package for the actual configuration management. Make sure you are familiar with illuminatech/config package before attempting to use this one.

First of all, you need to setup persistent configuration for your application, specifying the particular configuration items, which should be editable from Nova admin panel. For example:

<?php

namespace App\Providers;

use Illuminatech\Config\Providers\AbstractPersistentConfigServiceProvider;

class PersistentConfigServiceProvider extends AbstractPersistentConfigServiceProvider
{
    protected function items(): array
    {
        return [
            'app.name' => [
                'label' => __('Application name'),
                'rules' => ['sometimes', 'required'],
            ],
            'app.debug' => [
                'label' => __('Debug mode enabled'),
                'rules' => ['sometimes', 'required', 'boolean'],
                'cast' => 'boolean',
            ],
            'app.env' => [
                'label' => __('Application environment'),
                'rules' => ['sometimes', 'required'],
            ],
            // ...
        ];
    }

    // ...
}

Do not forget to register your persistent config service provider in "providers" section at "config/app.php":

<?php

return [
    // ...
    'providers' => [
        // ...
        App\Providers\PersistentConfigServiceProvider::class,
    ],
    // ...
];

Next, you should register the \Illuminatech\NovaConfig\NovaConfig tool within Nova at your NovaServiceProvider:

<?php

namespace App\Providers;

use Laravel\Nova\NovaApplicationServiceProvider;

class NovaServiceProvider extends NovaApplicationServiceProvider
{
    public function tools()
    {
        return [
            new \Illuminatech\NovaConfig\NovaConfig(),
            // ...
        ];
    }
}

Once it is done the new tool called "Settings" will appear at the Nova sidebar menu, leading to the configuration setup form.

Field Configuration

The form field to be used for the particular configuration item management defined via \Illuminatech\Config\Item::$options. By default, a regular text input will be used for the item. In case \Illuminatech\Config\Item::$cast is set to "bool" or "boolean", the checkbox field will be used. The dropdown (e.g. select) input will be rendered in case 'options' array provided. You can manually define the exact Nova field to be used, using 'component' key. For example:

<?php

namespace App\Providers;

use Illuminatech\Config\Providers\AbstractPersistentConfigServiceProvider;

class PersistentConfigServiceProvider extends AbstractPersistentConfigServiceProvider
{
    protected function items(): array
    {
        return [
            'app.name' => [
                'label' => __('Application name'),
                'rules' => ['sometimes', 'required'],
                // renders regular text input
            ],
            'app.debug' => [
                'label' => __('Debug mode enabled'),
                'rules' => ['sometimes', 'required', 'boolean'],
                'cast' => 'boolean', // renders checkbox input
            ],
            'app.env' => [
                'label' => __('Application environment'),
                'rules' => ['sometimes', 'required'],
                'options' => [ // dont't mess `Item::$options` with drop-down options!
                    'options' => [ // renders drop-down input
                        ['value' => 'production', 'label' => 'Production'],
                        ['value' => 'local', 'label' => 'Local'],
                        ['value' => 'testing', 'label' => 'Testing'],
                    ],
                ],
            ],
            'app.description' => [
                'label' => __('Application description'),
                'rules' => ['sometimes', 'required'],
                'options' => [
                    'component' => 'textarea-field', // renders textarea input
                ],
            ],
            // ...
        ];
    }

    // ...
}

In general any Nova field, which allowed to be used for resource management form (e.g. create/update record form), could be used for the particular config item. However, some fields require extra configuration parameters, which you'll have to setup manually. In order to get a proper configuration options, you can setup the field, you are interested with, for some of your Nova resources, then navigate to this resource's creation form and search in browser network console for the XHR request to URL like http://example.com/nova-api/your-resource-name/creation-fields. Its response contains JSON with key "fields", within which you can find the proper configuration for your field.

Access Restriction

You can restrict access to the application configuration setup form using regular tool's canSee() method provided by Nova. For example:

<?php

namespace App\Providers;

use Laravel\Nova\NovaApplicationServiceProvider;

class NovaServiceProvider extends NovaApplicationServiceProvider
{
    public function tools()
    {
        return [
            (new \Illuminatech\NovaConfig\NovaConfig())
                ->canSee(function ($request) {
                    return $request->user(config('nova.guard'))->is_super_admin;
                }),
            // ...
        ];
    }
}

Localization

All static text used within this extension is translatable via Laravel localization feature. You can publish the override for translations using following command:

php artisan vendor:publish --provider="Illuminatech\NovaConfig\NovaConfigServiceProvider" --tag=lang

illuminatech/nova-config 适用场景与选型建议

illuminatech/nova-config 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.27k 次下载、GitHub Stars 达 12, 最近一次更新时间为 2020 年 08 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「config」 「nova」 「laravel」 「Settings」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 illuminatech/nova-config 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 illuminatech/nova-config 我们能提供哪些服务?
定制开发 / 二次开发

基于 illuminatech/nova-config 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4.27k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 13
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 12
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2020-08-18