定制 supplycart/settings 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

supplycart/settings

最新稳定版本:3.0.0

Composer 安装命令:

composer require supplycart/settings

包简介

Model settings for Laravel

README 文档

README

Allows eloquent models to have its own settings

Installation

To install, run this on your Laravel installation:

composer require supplycart/settings

Then publish the migration file:

php artisan vendor:publish --tag=migrations --provider=Supplycart\Settings\Providers\SettingsServiceProvider

Usage

To use, you just need to implement the Supplycart\Settings\Contracts\HasSettings contract and use Supplycart\Settings\Traits\HasSettings trait:

use Supplycart\Settings\Contracts\HasSettings as HasSettingsContract;
use Supplycart\Settings\Traits\HasSettings;

class User extends Model implements HasSettingsContract
{
    use HasSettings;
    
    public function getDefaultSettings(): array
    {
        return [];
    }
}

Methods

getSetting($key, $default = null)

Retrieve model setting by key. You can use dot notations to get nested setting e.g

$user->getSetting('timezone', 'Asia/Kuala_Lumpur');
$user->getSetting('lang', 'en_my');
$user->getSetting('subscription.newsletter', false);

setSetting($key, $value)

Set model setting using key. You can use dot notation same like getSetting method e.g

$user->setSetting('timezone', 'UTC');
$user->setSetting('lang', 'en_us');
$user->setSetting('subscription.newsletter', true);

getSettings()

Get all settings. It will return array of settings

$settings = $user->getSettings(); // ['timezone' => 'UTC', 'lang' => 'en_us', 'subscription' => ['newsletter' => true]];

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-12-26