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

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

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

grhone/laravel-settings

最新稳定版本:v1.0.0

Composer 安装命令:

composer require grhone/laravel-settings

包简介

A Laravel package to add settings to your models.

README 文档

README

A Laravel package to manage settings for any Eloquent model. This package allows you to attach settings to any model using the HasSettings trait, retrieve settings with default values, and delete settings.

Installation

  1. Install the package via Composer:

    composer require grhone/laravel-settings
  2. Add the service provider to config/app.php if using Laravel version below 5.5:

    'providers' => [
        // Other service providers...
        Grhone\LaravelSettings\SettingsServiceProvider::class,
    ],
  3. Publish the migration file:

    php artisan vendor:publish --provider="Grhone\LaravelSettings\SettingsServiceProvider" --tag="migrations"
  4. Run the migrations:

    php artisan migrate

Usage

Using the HasSettings Trait

To use settings with your Eloquent models, simply add the HasSettings trait to your model:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Grhone\LaravelSettings\Traits\HasSettings;

class Event extends Model
{
    use HasSettings;

    public function getWebsiteBannerFilename()
    {
        // Get the setting with a default value
        return $this->getSetting('websiteBannerFilename', 'default_banner.jpg');
    }
}

Available Methods

getSetting($key, $default = null)

Retrieve the setting value for a given key. If the setting does not exist, the default value is returned.

$banner = $event->getSetting('websiteBannerFilename'); // without default value
$banner = $event->getSetting('websiteBannerFilename', 'default_banner.jpg'); // with default value

setSetting($key, $value)

Set the setting value for a given key.

$event->setSetting('websiteBannerFilename', 'banner123.jpg');

deleteSetting($key)

Delete the setting for a given key.

$event->deleteSetting('websiteBannerFilename');

Contributing

Thank you for considering contributing to the Laravel Settings Package! You can contribute in many ways, including:

  • Reporting a bug
  • Discussing the current state of the code
  • Submitting a fix
  • Proposing new features

License

The Laravel Settings Package is open-source software licensed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

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