承接 owowagency/laravel-settings 相关项目开发

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

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

owowagency/laravel-settings

Composer 安装命令:

composer require owowagency/laravel-settings

包简介

A package of settings features for the Laravel framework.

README 文档

README

Total Downloads Latest Stable Version

A package of settings features for the Laravel framework.

Installation

Installing this package can be done easily via the following Artisan command.

composer require owowagency/laravel-settings

Setup

To install all the vendor files you can run the following command.

php artisan vendor:publish --provider="OwowAgency\LaravelSettings\LaravelSettingsServiceProvider"

This will copy all the vendor files, including configuration, migrations and resources. If you wish to only install certain files you can use the command described in the next paragraphs.

Config

If you wish to publish the configuration file, you can use the following command:

php artisan vendor:publish --provider="OwowAgency\LaravelSettings\LaravelSettingsServiceProvider" --tag=config

Settings

The settings configuration holds all the values which can be used within the application. Each setting should have a unique key. For setting the key we would recommend using a package like Laravel Enum. Beside the key, we use the following attributes:

  • title (default: null): here you can store a small title of the setting.
  • description (default: null): a description about the setting which you might want to display to the user.
  • type (default: string): the variable type of the setting (the type should be acceptable by the settype() method).
  • default (default: null): the default value which will be used if the user hasn't stored the value in the database yet.
  • nullable (default: true): indicates if this setting may have the null value.

Table

The table_name configuration holds the value which is being used for the table name. By default, this has been set to settings, but if you wish to use a different table name you can change it with this configuration value.

Resources

The package uses Laravel its API Resources. We ship the package with one resource, which will return the setting model. If you wish to use a custom resource, you can specify them in this list.

Migrations

If you wish to publish the migrations, you can use the following command:

php artisan vendor:publish --provider="OwowAgency\LaravelSettings\LaravelSettingsServiceProvider" --tag=migrations

Routes

To set up all the routes needed for this package you can call the setting macro on the Route facade. By doing so, all the routes which are required by this package will be available to call.

Route::settings('users', App\Models\User::class);

After adding this to one of your routes files (i.e. routes/api.php), the following two routes will be available.

Index

This route can be used to index all the settings of a user: GET /users/{user}/settings. This route will always return all configured settings in the settings config value. Also, values which are not yet stored for the authenticated user. The package will then use the default configured value.

Response

[
    {
        "title": "Receive commercial emails",
        "description": "Would you like to receive commercial emails for our marketing campaign?",
        "type": "bool",
        "default": false,
        "nullable": false,
        "key": "wants_promotion_emails",
        "value": false
    }
]

Update

This route can be used to update the given setting values: PATCH /users/{user}/settings.

Request

[
    {
        "key": "wants_promotion_emails",
        "value": true
    } 
]

Response

[
    {
        "title": "Receive commercial emails",
        "description": "Would you like to receive commercial emails for our marketing campaign?",
        "type": "bool",
        "default": false,
        "nullable": false,
        "key": "wants_promotion_emails",
        "value": true
    }
]

Usage

If you want a certain model (we'll use the user model in this example) to have settings you can add the OwowAgency\LaravelSettings\Models\Concerns\HasSettings trait to the model. First you should add the OwowAgency\LaravelSettings\Models\Concerns\HasSettingsInterface to the model. Your model could look like this.

<?php

namespace App\Models;

use Illuminate\Foundation\Auth\User as BaseUser;
use OwowAgency\LaravelSettings\Models\Concerns\HasSettings;
use OwowAgency\LaravelSettings\Models\Contracts\HasSettingsInterface;

class User extends BaseUser implements HasSettingsInterface
{
    use HasSettings;
}

Now, to get a certain config value from the user you can do this:

$user->settings->getValue('wants_promotion_emails');

// Or

$user->settings->wants_promotion_emails;

owowagency/laravel-settings 适用场景与选型建议

owowagency/laravel-settings 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 742 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 11 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 742
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2020-11-02