Installation Add the bundle via Composer (if still maintained):
composer require customscripts/settings-bundle
Register the bundle in config/app.php under providers:
CustomScripts\SettingsBundle\SettingsBundle::class,
Publish Configuration Run:
php artisan vendor:publish --provider="CustomScripts\SettingsBundle\SettingsBundle" --tag="config"
This generates a config file at config/settings.php.
Define a Setting
In config/settings.php, add a new setting under the settings key:
'settings' => [
'app' => [
'name' => 'My App',
'debug_mode' => false,
],
],
Access a Setting
Retrieve values via the Settings facade:
use CustomScripts\SettingsBundle\Facades\Settings;
$appName = Settings::get('app.name'); // Returns 'My App'
Environment-Specific Overrides
Use settings.php to define environment-specific values (e.g., debug_mode for local vs. production).
Example:
'settings' => [
'app' => [
'debug_mode' => env('APP_DEBUG', false),
],
],
Caching Settings
Enable caching in config/settings.php:
'cache' => [
'enabled' => true,
'ttl' => 60, // Cache for 60 minutes
],
Clear cache manually:
php artisan settings:clear-cache
Service Provider Binding Bind settings to a service provider for dependency injection:
public function register()
{
$this->app->singleton('settings', function () {
return Settings::get('app');
});
}
Validation Rules Use settings in Form Requests:
public function rules()
{
return [
'max_upload_size' => 'required|numeric|max:'.Settings::get('app.max_upload_size'),
];
}
Event Listeners Trigger actions based on settings:
public function handle()
{
if (Settings::get('app.debug_mode')) {
Log::debug('Debug mode enabled');
}
}
No Active Maintenance The bundle is archived and not recommended for production. Consider alternatives like:
spatie/laravel-settingsconfig() + env() system.Limited Documentation The README is minimal. Expect undocumented behaviors (e.g., caching logic, fallback values).
No Database Backend
Settings are file-based only (config/settings.php). For dynamic updates, you’ll need to:
php artisan config:clear
Check Cache If settings aren’t updating, verify cache:
php artisan settings:clear-cache
php artisan config:clear
Fallback Values The bundle may not handle missing keys gracefully. Use null coalescing:
$value = Settings::get('app.nonexistent', 'default');
Custom Storage
Override the storage handler by binding a new settings.storage service in a provider:
$this->app->bind('settings.storage', function () {
return new CustomSettingsStorage();
});
Validation Layer
Add validation logic by extending the bundle’s SettingsManager:
use CustomScripts\SettingsBundle\SettingsManager;
class ExtendedSettingsManager extends SettingsManager
{
public function get($key, $default = null)
{
$value = parent::get($key, $default);
// Add custom validation here
return $value;
}
}
Then rebind the service:
$this->app->singleton('settings.manager', function () {
return new ExtendedSettingsManager();
});
Array vs. Dot Notation The bundle supports both:
Settings::get(['app', 'name']); // Works
Settings::get('app.name'); // Also works
Boolean Values
Ensure boolean settings are explicitly typed in config/settings.php:
'debug_mode' => true, // Not 'debug_mode' => 'true'
How can I help you explore Laravel packages today?