承接 devloops/nova-system-settings 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

devloops/nova-system-settings

Composer 安装命令:

composer require devloops/nova-system-settings

包简介

A Laravel Nova tool which provides the ability to define your system settings in a beautiful UI and code implementation.

README 文档

README

Laravel Nova System Settings Tool

Latest Version on Packagist License Total Downloads

The Missing Laravel Nova System Settings Tool.

This packages saves the times for you when creating the system settings part of your project, it handles the UI in a very intuitive convenient way. It has a straightforward, Nova-Like implementation, and it was built over Spatie's laravel-settings package.

  • A look at Spatie's package docs is needed to keep track of how things are going.

Installation

composer require devloops/nova-system-settings

Implementation

The usage of this package is very simple as creating a class that extends Devloops\NovaSystemSettings\Contracts\SystemSettings abstract class, which itself extends the Spatie\LaravelSettings\Settings class of Spatie's laravel-settings packages, then register the tool inside the NovaServiceProvider giving it an array of the settings you defined for your system.

Below is a full of example

1- Create your settings class as follows.

<?php

namespace App\Nova\Settings\General;

use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Textarea;
use Devloops\NovaSystemSettings\Contracts\SystemSettings;


class SiteSettings extends SystemSettings
{

    public ?string $title;

    public ?string $slogan;

    public ?string $email;

    public ?string $phoneNumber;

    public ?string $address;

    public static function group(): string
    {
        return 'general';
    }

    public static function title(): string
    {
        return __('Site Settings');
    }

    public static function icon(): string
    {
        return 'cog';
    }

    public static function name(): string
    {
        return 'site_settings';
    }

    public static function fields(): array
    {
        return [
            Text::make(__('Site Title'), 'title'),
            Text::make(__('Site Slogan'), 'slogan'),
            Text::make(__('Site Email'), 'email'),
            Text::make(__('Site Phone Number'), 'phoneNumber'),
            Textarea::make(__('Site Address'), 'address'),
        ];
    }
}
<?php

namespace App\Nova\Settings\General;

use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Password;
use Devloops\NovaSystemSettings\Contracts\SystemSettings;

class MailSettings extends SystemSettings
{

    public ?string $mailer;

    public ?string $host;

    public ?int $port;

    public ?string $username;

    public ?string $password;

    public ?string $encryption;

    public static function group(): string
    {
        return 'general';
    }

    public static function title(): string
    {
        return __('Mail Settings');
    }

    public static function icon(): string
    {
        return 'mail';
    }

    public static function name(): string
    {
        return 'mail_settings';
    }

    public static function fields(): array
    {
        return [
            Select::make(__('Mailer'), 'mail')
                  ->options([
                      'smtp'     => __('SMTP'),
                      'sendmail' => __('Sendmail'),
                      'mailgun'  => __('Mailgun'),
                  ]),
            Text::make(__('Host'), 'host'),
            Number::make(__('Port'), 'port'),
            Text::make(__('Username'), 'username'),
            Password::make(__('Password'), 'password'),
            Select::make(__('Encryption'), 'encryption')
                  ->options([
                      null  => __('None'),
                      'tls' => __('TLS'),
                      'ssl' => __('SSL'),
                  ]),
        ];
    }
}
<?php

namespace App\Nova\Settings\Store;

use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Boolean;
use Devloops\NovaSystemSettings\Contracts\SystemSettings;

class OrderSettings extends SystemSettings
{
    public ?float $minOrder;

    public ?bool $allowGuestCheckout;

    public ?bool $allowFreeShipping;

    public static function group(): string
    {
        return 'store';
    }

    public static function title(): string
    {
        return __('Order Settings');
    }

    public static function icon(): string
    {
        return 'shopping-cart';
    }

    public static function name(): string
    {
        return 'order_settings';
    }

    public static function fields(): array
    {
        return [
            Number::make(__('Minimum Order'), 'minOrder'),
            Boolean::make(__('Allow Guest Checkout'), 'allowGuestCheckout'),
            Boolean::make(__('Allow Free Shipping'), 'allowFreeShipping'),
        ];
    }
}
<?php

namespace App\Nova\Settings\Tenant\Store;

use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Boolean;
use Devloops\NovaSystemSettings\Contracts\SystemSettings;

class CustomerSettings extends SystemSettings
{

    public ?string $loginVia;

    public ?bool $requiresEmailVerification;

    public ?int $canRegister;

    public static function group(): string
    {
        return 'store';
    }

    public static function title(): string
    {
        return __('Customer Settings');
    }

    public static function icon(): string
    {
        return 'user';
    }

    public static function name(): string
    {
        return 'customer_settings';
    }

    public static function fields(): array
    {
        return [
            Select::make(__('Login Via'))
                  ->options([
                      'email'        => __('Email'),
                      'phone_number' => __('Phone Number'),
                  ]),
            Boolean::make(__('Requires Email Verification'), 'requiresEmailVerification'),
            Boolean::make(__('Can Register'), 'canRegister'),
        ];
    }
}

The above classes implements five methods that are abstractly inherited from the SystemSettings class, the methods are:

    /**
     * Get system settings group.
     *
     * @return string
     */
    abstract public static function group(): string;

    /**
     * Get system settings title.
     *
     * @return string
     */
    abstract public static function title(): string;

    /**
     * Get system settings icon.
     *
     * @return string
     */
    abstract public static function icon(): string;

    /**
     * Get system settings name.
     *
     * @return string
     */
    abstract public static function name(): string;

    /**
     * Return system settings fields.
     *
     * @return array
     */
    abstract public static function fields(): array;

The comments on the methods tells each methods goal.

2- Register all your settings via the tool() method in the App\Providers\NovaServiceProvider like the example below.

use App\Nova\Settings\General\SiteSettings;
use App\Nova\Settings\General\MailSettings;
use App\Nova\Settings\Store\OrderSettings;
use App\Nova\Settings\Store\CustomerSettings;

    public function tools(): array
    {
        return [
            NovaSystemSettings::make([
                //General
                SiteSettings::make(),
                MailSettings::make(),

                //Store
                OrderSettings::make(),
                CustomerSettings::make()
            ]),
        ];
    }

4- The system settings groups title are translatable, you need to create a locale file resources/lang/en/system-settings.php

<?php

return [
    'groups' => [        
        'general'          => 'General',
        'store'            => 'Store',
    ],
];

5- System settings internal usage is pretty simple, as Spatie's laravel-settings package behaves, you can simply use dependency injection to inject the settings class in either your services, controllers, repositories or any other place in your system.

<?php

namespace App\Http\Controllers\Api\V1;

use App\Nova\Settings\Store\CustomerSettings;
use App\Http\Requests\Api\V1\Auth\SendOtpRequest;

class AuthController extends ApiController
{

    public function __construct(
        public CustomerSettings $customerSettings
    ) {
    }

    public function sendOtp(SendOtpRequest $request)
    {
        dd($this->customerSettings->loginVia);
    }
}

Screenshots

Screenshot 1

Screenshot 2

Screenshot 3

Screenshot $

Credits

License

The MIT License (MIT). Please see License File for more information.

devloops/nova-system-settings 适用场景与选型建议

devloops/nova-system-settings 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.43k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2024 年 05 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 6.43k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-05-10