vendocrat / laravel-settings
Persistent, application-wide settings for Laravel 5.
Requires
- php: >=5.5.9
- doctrine/dbal: 2.5.x
- illuminate/database: >=5.1
- illuminate/filesystem: >=5.1
- illuminate/support: >=5.1
Requires (Dev)
- mockery/mockery: 0.9.*
This package is not auto-updated.
Last update: 2022-02-01 12:50:38 UTC
README
Laravel Settings
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!
Installation
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 ];
Configuration
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, ...).
Migration
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
Usage
Get all settings
$settings = \Setting::all();
Check if a setting exists
\Setting::has($key);
Get a setting
$setting = \Setting::get($key);
Add/update a setting
\Setting::set($key, $value);
Delete a setting
\Setting::forget($key);
Delete all settings
\Setting::flush();
Save your updates (set, forget, flush)
\Setting::save();
Example
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"
]
My Edits
- restructured folders & files
- uses Eloquent models for database driver with soft deleting
- add interface contract
- removed middleware
To-Dos
- 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)
License
Licensed under MIT license.
Author
Handcrafted with love by Alexander Manfred Poellmann for vendocrat in Vienna & Rome.
Based on Laravel Settings by Andreas Lutro.