Persistent, application-wide settings for Laravel 5.
Attention: This package is a work in progress, please use with care and be sure to report any issues!
Require the package from your composer.json
file
"require": {
"vendocrat/laravel-settings": "dev-master"
}
and run $ composer update
or both in one with $ composer require vendocrat/laravel-settings
.
Next register the service provider and (optional) facade to your config/app.php
file
'providers' => [
// Illuminate Providers ...
// App Providers ...
vendocrat\Settings\SettingsServiceProvider::class
];
'providers' => [
// Illuminate Facades ...
'Setting' => vendocrat\Settings\Facades\Setting::class
];
Laravel Settings includes an optional config file. Get started buy publishing it:
$ php artisan vendor:publish --provider="vendocrat\Settings\SettingsServiceProvider" --tag="config"
This will create a config/settings.php
file where you can set for example which driver you want to use (JSON file, database, ...).
Note: You'll only need to complete this step when using the database driver.
If you want to store your settings in your database, you'll have to set 'driver'
in your config/settings.php
file to 'database'
and publish the migration like so:
$ php artisan vendor:publish --provider="vendocrat\Settings\SettingsServiceProvider" --tag="migrations"
Afterwards you'll have to run the artisan migrate command:
$ php artisan migrate
$settings = \Setting::all();
\Setting::has($key);
$setting = \Setting::get($key);
\Setting::set($key, $value);
\Setting::forget($key);
\Setting::flush();
\Setting::save();
The following example would store the setting 'bar'
with the key 'foo'
, then update it to 'bars'
, save it and then die & dump all current settings, which is only one unique 'foo'
key-value pair.
\Setting::set('foo', 'bar');
\Setting::set('foo', 'bars');
\Setting::save();
dd(\Setting::all());
Results in
array [
"foo" => "bars"
]
- restructured folders & files
- uses Eloquent models for database driver with soft deleting
- add interface contract
- removed middleware
- add Redis support
- add option to group settings (e.g. config/user/...)
- add logic to automatically render input forms in the frontend for settings (like a simple App Settings view or so)
Licensed under MIT license.
Handcrafted with love by Alexander Manfred Poellmann for vendocrat in Vienna & Rome.
Based on Laravel Settings by Andreas Lutro.