rdcstarr / laravel-settings
A simple settings package for Laravel.
v1.1.3
2025-09-16 15:52 UTC
Requires
- php: ^8.0
- illuminate/contracts: ^11.0||^12.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.8
- orchestra/testbench: ^10.0.0||^9.0.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
README
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
- Changelog for more information on what has changed recently.
- Contributing for details.
- Security Vulnerabilities on how to report security vulnerabilities.
๐ฅ Credits
๐ License
- License for more information.