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

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

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

egough/laravel-settings

Composer 安装命令:

composer require egough/laravel-settings

包简介

Database-backed application and model settings for Laravel.

README 文档

README

alt text

Latest Version on Packagist Total Downloads License Tests

Database-backed application and model settings for Laravel.

Provides a simple, typed and cacheable way to store dynamic configuration outside of .env and static config files, including per-model settings such as user or team preferences.

Quick Example

// Application setting
settings()->set('site.name', 'My Application');

settings()->get('site.name');


// Model-specific setting
$user->settings()->set('ui.theme', 'dark');

$user->settings()->get('ui.theme');


// Feature flag
if (flag('billing.enabled')) {
    // Feature enabled
}

Blade usage:

@hasFlag('billing.enabled')
    <x-billing-panel />
@endhasFlag

<title>@setting('site.name')</title>

When Should I Use This Package?

Use this package when your application needs configuration that can change at runtime without modifying environment variables or deployment configuration.

Typical use cases include:

Application settings

  • Site name or branding
  • Feature toggles
  • Maintenance or runtime configuration
  • Admin-managed options

Model settings

  • User preferences (theme, notifications, dashboard layout)
  • Team or organisation configuration
  • Account-specific options
  • Per-project or per-resource metadata

This package is intended for dynamic configuration stored in the database and accessed consistently across your application.

When Not to Use It

You should continue using Laravel configuration or environment variables for:

  • Database credentials
  • API keys and secrets
  • Environment-specific infrastructure configuration
  • Values required during application boot

In general:

  • .env → infrastructure and secrets
  • config/*.php → static application configuration
  • egough/laravel-settings → runtime, database-driven configuration

Installation

composer require egough/laravel-settings:^1.0

Publish configuration and migrations:

php artisan vendor:publish --tag=settings-config
php artisan vendor:publish --tag=settings-migrations
php artisan vendor:publish --tag=settings-model-migrations
php artisan migrate

Application Settings

Global settings are accessible anywhere in your application.

Helper

settings()->set('site.name', 'My Application');

settings()->get('site.name');

Facade

use Settings;

Settings::set('site.name', 'My Application');
Settings::get('site.name');

Dependency Injection

use Egough\LaravelSettings\SettingsManager;

public function __construct(
    private SettingsManager $settings
) {}

$this->settings->get('site.name');

Model Settings

Settings can be attached to any Eloquent model.

Add the trait:

use Egough\LaravelSettings\Traits\HasSettings;

class User extends Model
{
    use HasSettings;
}

Usage:

$user = User::find(1);

$user->settings()->set('ui.theme', 'dark');

$user->settings()->get('ui.theme');

Retrieve all settings:

$user->settings()->all();

Remove a setting:

$user->settings()->forget('ui.theme');

Feature Flags

Feature flags are boolean settings.

flag('billing.enabled');

Flag::enabled('billing.enabled');

With fallback:

flag('beta.feature', false);

Blade Directives

@hasSetting('site.name')
@endhasSetting

@hasFlag('billing.enabled')
@endhasFlag

<title>@setting('site.name')</title>

Default Values

Define defaults in config/settings.php:

'defaults' => [
    'site.name' => 'Laravel App',
];

Lookup order:

  1. Database value
  2. Config default
  3. Provided fallback

Caching

Settings are cached automatically.

Clear cache manually:

php artisan settings:clear-cache

Testing

Install development dependencies:

composer install

Run the test suite:

composer test

Or run PHPUnit directly:

vendor/bin/phpunit

The package tests use a lightweight in-memory SQLite setup for repository integration coverage, so no external database service is required.

Artisan Commands

php artisan settings:get site.name
php artisan settings:set site.name "My App"
php artisan settings:clear-cache

Requirements

  • PHP 8.2+
  • Laravel 10, 11, 12, or 13

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固