Web-Application settings for Laravel. An easy way to use yet powerful way to store and retrieve settings in your database. Use Settings for storing things like website title or general variables that are used throughout your development, and want to make the modification of these values easy., (*1)
Couple it together with a backend page to add/modify/delete settings on the fly, and you have yourself the perfect settings page., (*2)
In your Laravel project's composer.json file, add settings
as a dependency in the require object:, (*3)
"mschinis/settings": "dev-master"
Use composer update
for composer to update the dependencies and download the package., (*4)
Once installed, add the ServiceProvider to your provider array and the Setting alias to your aliases array within app/config/app.php
:, (*5)
'providers' => array( 'Mschinis\Settings\SettingsServiceProvider' ) 'aliases' => array( 'Setting' => 'Mschinis\Settings\Facades\Setting' )
Setting up the database table is as easy as 1-2-3., (*6)
php artisan migrate:publish mschinis/settings
php artisan migrate
Wait, no 3rd step? Yup. Tha-Tha-Tha-That's all folks! Enjoy using the settings package :), (*7)
The package only stores the settings at the database, but more setting stores like redis/json file will be added soon.
The default table is settings
. If you wish to modify the table name, you can do so by publishing the configuration file using php artisan config:publish mschinis/settings
and changing the table in the published config file., (*8)
You can either access the setting store via its facade. A simple usage example is shown below., (*9)
<?php Setting::set('app.title', 'My awesome website'); // Set a new setting / Update an existing setting $title_setting = Setting::get('app.title', 'default value'); // Retrieve the value of a setting, with a default fallback $title_setting = Setting::get('app.title'); // Retrieve the value of a setting with no default fallback $title_object = Setting::getObject('app.title') // Retrieve the Eloquent object model of the 'app.title' setting. Setting::forget('app.title'); // Remove a setting from the database $settings = Setting::all(); // Retrieve all settings from the database ?>
If the package fails to find a specific setting, and a default value is not provided, an exception will be thrown. To handle the exception you can use, (*10)
Open an issue on GitHub if you have any problems or suggestions., (*11)
The contents of this repository is released under the MIT license., (*12)