定制 utyemma/larasetting 二次开发

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

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

utyemma/larasetting

最新稳定版本:v1.08

Composer 安装命令:

composer require utyemma/larasetting

包简介

Quick and easy app settings for laravel applications

README 文档

README

Description

LaraSettings is a Laravel package that simplifies the management of application settings. It provides a structured and extensible way to define, retrieve, and update settings stored in the database. It includes useful commands for generating and seeding settings classes, making it easy to customize for various use cases.

Table of Contents

  1. Requirements
  2. Installation
  3. Usage
  4. Contributing
  5. Maintainers
  6. License

Requirements

  • PHP 8.0+
  • Laravel 9.0+

Installation

  1. Install the package via Composer:

    composer require utyemma/larasettings
  2. Publish the migration file:

    php artisan vendor:publish --tag=larasettings-migrations
  3. Run the migrations to create the settings table:

    php artisan migrate

Usage

Defining a Settings Class

Use the make:setting command to create a new settings class:

php artisan make:setting ExampleSettings

This will generate a new settings class in the App\Settings namespace. Define your options, labels, and casts within the class to tailor it to your application's needs.

Seeding Settings

To seed settings into the database, use the settings:seed command:

php artisan settings:seed --class=ExampleSettings

Replace ExampleSettings with the name of your settings class. This will populate the database with the default attributes and values defined in the class.

Retrieving and Updating Settings

You can interact with settings using dynamic property access or methods:

Retrieving a Setting

$exampleSettings = app(\App\Settings\ExampleSettings::class);
$value = $exampleSettings->some_key; // Retrieve the value of a setting

Updating a Setting

$exampleSettings->some_key = 'New Value'; // Update the value of a setting

Bulk Updating Settings

$exampleSettings->update([
    'key1' => 'Value1',
    'key2' => 'Value2',
]);

Fetching All Settings

$settingsArray = $exampleSettings->toArray();

Strict Mode

LaraSettings operates in strict mode by default. Strict mode ensures that only settings defined in the options array of a settings class can be updated or created. This prevents accidental changes to undefined settings. When enabled, attempting to update an undefined setting will throw an exception. Ensure that all valid keys are listed in the options array of your settings class.

Disabling Strict Mode

If you want to allow dynamic creation of settings that are not predefined in the options array, you can set the $strict property to false in your settings class:

protected $strict = false;

Contributing

Contributions are welcome! To contribute:

  1. Fork the repository.
  2. Create a feature branch.
  3. Submit a pull request.

Maintainers

  • Utibe-Abasi Emmanuel (GitHub)

License

This package is open-sourced software licensed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-11-20