A minimal and powerful settings package for Laravel with caching, type casting, and bulk operations.
- Simple key-value storage
- Automatic type casting (strings, integers, floats, booleans, arrays, JSON)
- Built-in caching for performance
- Bulk operations for setting/getting multiple values
- Facade support
- Configurable cache TTL
- Database storage
You can install the package via composer:
composer require amdadulhaq/setting-laravel- PHP 8.2, 8.3, 8.4, or 8.5
- Laravel 10, 11, 12, or 13
You can publish and run the migrations with:
php artisan vendor:publish --tag="setting-laravel-migrations"
php artisan migrateOptionally publish the config file:
php artisan vendor:publish --tag="setting-laravel-config"use AmdadulHaq\Setting\Facades\Setting;
Setting::set('app_name', 'Laravel');
return Setting::get('app_name');
// Laravel
Setting::remove('app_name');
// true
Setting::has('app_name');
// falsesetting()->set('app_name', 'Laravel');
return setting()->get('app_name');
// Laravel
return setting()->remove('app_name');
// trueThe package automatically casts values to their appropriate types:
setting()->set('string_value', 'Hello');
setting()->set('integer_value', 100);
setting()->set('float_value', 15.5);
setting()->set('boolean_value', true);
setting()->set('array_value', ['foo' => 'bar']);
setting()->set('json_value', ['nested' => ['key' => 'value']]);
setting()->get('integer_value'); // Returns: 100 (int)
setting()->get('boolean_value'); // Returns: true (bool)
setting()->get('array_value'); // Returns: ['foo' => 'bar'] (array)setting()->get('nonexistent_key', 'default_value');
// default_value// Set multiple settings at once
setting()->setMultiple([
'app_name' => 'Laravel',
'max_users' => 100,
'maintenance_mode' => false,
]);
// Get multiple settings at once
$settings = setting()->getMultiple(['app_name', 'max_users']);
// ['app_name' => 'Laravel', 'max_users' => 100]$allSettings = setting()->all();
// Returns a Collection of all settings// Manually flush the cache
setting()->flushCache();The config file allows you to configure caching behavior:
return [
'cache_enabled' => env('SETTING_CACHE_ENABLED', true),
'cache_key' => env('SETTING_CACHE_KEY', 'settings.cache'),
'cache_ttl' => env('SETTING_CACHE_TTL', 60 * 60 * 24), // 24 hours
];composer testPlease see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.