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

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

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

rdcstarr/laravel-settings

最新稳定版本:v1.3.2

Composer 安装命令:

composer require rdcstarr/laravel-settings

包简介

A simple settings package for Laravel.

README 文档

README

Latest Version on Packagist Tests Code Style Downloads

Simple settings management for Laravel — because configuration should be easy.

✨ Features

  • Cache built-in – automatic caching for blazing-fast reads
  • 🔄 Smart type casting – automatic conversion between strings, integers, booleans, arrays, and JSON
  • 📦 Batch operations – set multiple values at once with setMany()
  • 🛠️ Artisan commands – manage settings directly from the terminal
  • 💯 No exceptions – returns false on failure, never crashes your app

📦 Installation

Install the package via Composer:

composer require rdcstarr/laravel-settings

Automatic Installation (Recommended)

Run the install command to publish and run the migrations:

php artisan settings:install

Manual Installation

Alternatively, you can install manually:

  1. Publish the migrations:
php artisan vendor:publish --tag=settings-migrations
  1. Run the migrations:
php artisan migrate

🛠️ Artisan Commands

Manage your settings directly from the command line:

# List all settings
php artisan settings:list

# Get a specific setting
php artisan settings:get app.name

# Set a setting
php artisan settings:set app.name "My Application"

# Delete a setting
php artisan settings:delete old.setting [--force]

# Clear cache
php artisan settings:clear-cache [--force]

🔑 Usage

Basic Operations

// Get a setting (returns false if not found)
$name = settings()->get('app.name', 'Default Name');

// Set a setting (returns true on success, false if unchanged or failed)
settings()->set('app.name', 'My Application');

// Check if a setting exists
if (settings()->has('app.name')) {
    // Setting exists
}

// Delete a setting (returns true if deleted, false otherwise)
settings()->delete('old.setting');

// Get all settings
$all = settings()->all(); // Collection

Batch Operations

// Set multiple settings at once
settings()->setMany([
    'app.name' => 'My Application',
    'app.theme' => 'dark',
    'app.language' => 'en',
    'mail.driver' => 'smtp',
    'mail.host' => 'smtp.example.com',
]);

Helper Function

// Quick access with helper
$theme = settings('app.theme', 'light');

// Same as
$theme = settings()->get('app.theme', 'light');

Using the Facade

use Rdcstarr\Settings\Facades\Settings;

Settings::set('app.name', 'My App');
$name = Settings::get('app.name', 'Default');
Settings::delete('old.setting');

Cache Management

// Clear the cache (returns true on success)
settings()->flushCache();

Smart Type Casting

The package automatically handles type conversion:

// Integers
settings()->set('max_users', 100);
settings()->get('max_users'); // returns (int) 100

// Booleans
settings()->set('maintenance_mode', true);
settings()->get('maintenance_mode'); // returns (bool) true

// Arrays
settings()->set('config', ['key' => 'value']);
settings()->get('config'); // returns array

// Null values
settings()->set('optional', null);
settings()->get('optional'); // returns null

💡 Real-World Examples

// Application configuration
settings()->setMany([
    'site.name' => 'My Website',
    'site.description' => 'A wonderful site',
    'site.maintenance_mode' => false,
]);

// Feature flags
if (settings()->get('features.new_dashboard', false)) {
    return view('dashboard.new');
}

// User preferences
settings()->set("user.{$userId}.theme", 'dark');
settings()->set("user.{$userId}.language", 'en');

// Email settings
$mailConfig = [
    'mail.driver' => 'smtp',
    'mail.host' => 'smtp.mailtrap.io',
    'mail.port' => 2525,
    'mail.username' => 'user',
    'mail.password' => 'pass',
];
settings()->setMany($mailConfig);

// API keys and secrets
settings()->set('services.stripe.key', 'sk_test_...');
settings()->set('services.stripe.secret', 'whsec_...');

🧪 Testing

composer test

📖 Resources

  • Changelog for more information on what has changed recently. ✍️

👥 Credits

📜 License

  • License for more information. ⚖️

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固