l5starter/setting
Laravel 5.4 settings module for L5Starter admin. Adds settings pages/routes and menu entry, with publishable config, migrations, and seeder (SettingsTableSeeder) to bootstrap stored application settings.
Installation
Add to composer.json:
"require": {
"l5starter/setting": "5.4.x-dev"
}
Run:
composer update
Register Provider
Add to config/app.php under providers:
L5Starter\Setting\SettingServiceProvider::class,
Publish Config & Migrations Run:
php artisan vendor:publish --provider="L5Starter\Setting\SettingServiceProvider"
php artisan migrate
php artisan db:seed --class=SettingsTableSeeder
First Use Case Access settings via the facade:
use L5Starter\Setting\Facades\Setting;
$value = Setting::get('site_name');
Retrieving Settings
// Single value
$siteName = Setting::get('site_name');
// Multiple values
$settings = Setting::get(['site_name', 'site_email']);
Updating Settings
// Single value
Setting::set('site_name', 'New App Name');
// Multiple values
Setting::set([
'site_name' => 'Updated Name',
'site_email' => 'contact@example.com'
]);
Admin Panel Integration
admin.settings.*) for CRUD operations.resources/views/vendor/l5starter/admin/partials/sidebar.blade.php:
<li class="{{ Request::is('admin/settings*') ? 'active' : '' }}">
<a href="{{ route('admin.settings.index') }}">
<i class="fa fa-cog"></i> <span>{{ trans('l5starter::general.settings') }}</span>
</a>
</li>
Caching (Optional)
Enable caching in config/settings.php:
'cache' => true,
Clear cache manually when needed:
php artisan cache:clear
Scoped Settings Use namespaced keys for modular apps:
Setting::set('app.feature_x.enabled', true);
Validation Rules
Attach validation to settings in SettingsTableSeeder.php:
$this->call(SettingsTableSeeder::class);
// Extend with custom rules
Event Listeners
Listen for setting updates via SettingUpdated event:
Setting::updated(function ($key, $value) {
// Log or trigger side effects
});
Dynamic Configuration Override Laravel config dynamically:
$config = Setting::get('app.config');
config(['app' => $config]);
Missing Migrations
php artisan migrate after publishing will break setting retrieval.Cache Invalidation
cache: true is enabled, changes won’t reflect until cache is cleared.Setting::clearCache() in a post-update event.Namespace Collisions
.) in keys if they conflict with Laravel’s config system.app.feature_x.*).Seeder Overrides
db:seed multiple times may duplicate settings.Setting::setIfNotExists() in seeders.Admin Route Conflicts
admin.settings.* routes may clash with other admin packages.routes/web.php:
Route::namespace('Admin')->group(function () {
Route::resource('app-settings', 'SettingsController');
});
Check Published Config
Verify config/settings.php matches your expectations after publishing.
Log Missing Keys Use a fallback value to debug missing keys:
$value = Setting::get('missing_key', 'default_value');
Inspect Database
Directly query the settings table to verify data:
php artisan tinker
>>> \DB::table('settings')->get();
Disable Cache Temporarily
Set 'cache' => false in config/settings.php to rule out caching issues.
Custom Storage
Override the storage driver in config/settings.php:
'driver' => 'redis', // or 'database', 'cache'
Custom Validation
Extend the Setting facade to add validation:
Setting::extend('email', function ($value) {
return filter_var($value, FILTER_VALIDATE_EMAIL);
});
Localization
Translate setting labels in resources/lang/en/l5starter.php:
'settings' => [
'site_name' => 'Website Name',
],
API Access Expose settings via API by creating a controller:
Route::get('/api/settings', function () {
return Setting::all();
});
How can I help you explore Laravel packages today?