rdcstarr/laravel-settings

A simple settings package for Laravel.

v1.1.3 2025-09-16 15:52 UTC

This package is auto-updated.

Last update: 2025-09-16 15:52:37 UTC


README

Latest Version on Packagist Tests Code Style Downloads

Elegant package for managing application settings in Laravel โ€” with caching and multiple access methods.

โœจ Features

  • โšก Cache โ€“ built-in cache layer for speed
  • ๐ŸŽฏ Access โ€“ helper, facade, or DI
  • ๐Ÿ“ฆ Batch ops โ€“ set multiple values at once
  • ๐Ÿ”„ Fluent API โ€“ method chaining for clean code
  • ๐Ÿ—‚๏ธ Groups โ€“ organize settings by logical groups (e.g., admin, user, tenant) for scoped configuration

๐Ÿ“ฆ Installation

composer require rdcstarr/laravel-settings

Publish & migrate:

php artisan vendor:publish --provider="Rdcstarr\Settings\SettingsServiceProvider" --tag="migrations" // optional
php artisan migrate

๐Ÿ”‘ Usage

Set Values

// single
settings()->set('app.name', 'My App');

// batch
settings()->set([
    'mail.driver' => 'smtp',
    'mail.host' => 'smtp.example.com',
    'mail.port' => 587,
    'mail.encryption' => 'tls',
]);

// or use setMany for cleaner syntax
settings()->setMany([
    'app.theme' => 'dark',
    'app.language' => 'en',
    'app.timezone' => 'UTC',
]);

Get Values

$theme = settings('app.theme', 'light'); // with default
$all   = settings()->all();              // all values

// get multiple values at once
$config = settings()->getMany(['app.theme', 'app.language', 'app.timezone']);
// returns: ['app.theme' => 'dark', 'app.language' => 'en', 'app.timezone' => 'UTC']

Working with Groups

// set values in specific group
settings()->group('admin')->set('site_name', 'My Admin Panel');
settings()->group('user')->set('theme', 'dark');

// get values from specific group
$siteName = settings()->group('admin')->get('site_name', 'Default Site');
$userTheme = settings()->group('user')->get('theme', 'light');

// get all values from a group
$adminSettings = settings()->group('admin')->all();

Facade

use Rdcstarr\Settings\Facades\Settings;

Settings::set('app.name', 'My App');
$driver = Settings::get('mail.driver', 'smtp');

// working with groups via facade
Settings::group('admin')->set('dashboard_style', 'modern');
$style = Settings::group('admin')->get('dashboard_style', 'classic');

Extra Operations

settings()->has('app.name');       // check existence
settings()->forget('old.setting'); // delete
settings()->flushCache();          // clear cache

// group-specific operations
settings()->group('admin')->has('site_name');     // check in specific group
settings()->group('admin')->forget('old_config'); // delete from specific group
settings()->flushAllCache();                      // clear all groups cache

๐ŸŽจ Blade Directives

{{-- Simple settings --}}
@settings('app_name', 'Default')

{{-- Settings from specific group --}}
@settingsForGroup('admin', 'site_name', 'My Site')
@settingsForGroup('user', 'theme', 'light')

{{-- Conditional checks --}}
@hasSettings('maintenance_mode')
    <div class="alert">Maintenance mode active</div>
@endhasSettings

{{-- Conditional checks for specific group --}}
@hasSettingsForGroup('admin', 'debug_mode')
    <div class="debug-info">Debug mode enabled</div>
@endhasSettingsForGroup

{{-- More examples --}}
@settingsForGroup('mail', 'from_name', 'Laravel App')
@settingsForGroup('social', 'twitter_handle')

๐ŸŽฏ Artisan Commands

The package provides dedicated Artisan commands for managing settings directly from the command line:

List Settings

# List all settings from default group
php artisan settings:list

# List settings from a specific group
php artisan settings:list --group=admin

Set Settings

# Interactive mode (prompts for input)
php artisan settings:set

# Set with arguments
php artisan settings:set app.name "My Application"

# Set with specific group
php artisan settings:set site_name "Admin Panel" --group=admin

Get Settings

# Interactive mode
php artisan settings:get

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

# Get from specific group
php artisan settings:get site_name --group=admin

Delete Settings

# Interactive mode
php artisan settings:delete

# Delete specific setting
php artisan settings:delete old.setting

# Delete from group with force (skip confirmation)
php artisan settings:delete old_config --group=admin --force

Clear Cache

# Clear all cache (with confirmation)
php artisan settings:clear-cache

# Clear specific group cache
php artisan settings:clear-cache --group=admin

# Skip confirmation
php artisan settings:clear-cache --force

List Groups

# List all available groups
php artisan settings:groups

All commands feature interactive prompts using Laravel Prompts for a beautiful CLI experience with validation, confirmations, and colorful output.

๐Ÿ’ก Examples

// User preferences with groups
settings()->group('user_' . auth()->id())->setMany([
    'theme' => 'dark',
    'language' => 'en',
    'timezone' => 'Europe/London',
]);

// Admin configuration
settings()->group('admin')->setMany([
    'site_name' => 'My Application',
    'maintenance_mode' => false,
    'debug_enabled' => true,
]);

// Feature flags
if (settings()->group('features')->get('new_dashboard', false)) {
    // Enable new dashboard feature
}

// Multi-tenant settings
$tenantId = tenant()->id;
settings()->group("tenant_{$tenantId}")->set('branding_color', '#ff6b6b');

// Get user preferences in one call
$userPrefs = settings()->group('user_' . auth()->id())
    ->getMany(['theme', 'language', 'timezone']);

๐Ÿงช Testing

composer test

๐Ÿ“– Resources

๐Ÿ‘ฅ Credits

๐Ÿ“œ License