This is a package for Laravel that can be used to store and access settings for your application.
The settings are stored in a single database table. The default configuration stores this in a settings
table.
- Run
composer require robtrehy/laravel-application-settings
to include this in your project. - Publish the config file with the following command
php artisan vendor:publish --provider="RobTrehy\LaravelApplicationSettings\ApplicationSettingsServiceProvider" --tag="config"
- Modify the published configuration file to your requirements. The file is located at
config/application-settings.php
. - Add the
settings
table to the database. A migration file is included, just run the following commandThis will add the table defined in your configuration file to your database.php artisan vendor:publish --provider="RobTrehy\LaravelApplicationSettings\ApplicationSettingsServiceProvider" --tag="migrations" && php artisan migrate
Open config/application-settings.php
to adjust the packages configuration.
If this file doesn't exist, run
php artisan vendor:public --provider="RobTrehy\LaravelApplicationSettings\ApplicationSettingsServiceProvider" --tag="config"
to create the default configuration file.
Set table
, key
, and value
to match your requirements.
Laravel Application Settings uses the Laravel Cache driver to reduce the number of queries on your database. By default Laravel Caches using the file
driver. If you wish to disable this, you can use the null
driver.
The cache key supplied by Laravel Application Settings can be set by changing the cache.key
configuration value.
'database' => [
'table' => 'settings',
'key' => 'key',
'value' => 'value'
],
'cache' => [
'key' => 'application.settings'
]
Use this method to set a setting for the application
ApplicationSettings::set(string [setting], [value]);
The setting will be immediately saved to the database
Use this method to get the value of a setting for the application
Pass a second arguement to return a default value if the setting is not set, defaults to null
ApplicationSettings::get(string [setting], string [default] = null);
Use this method to get the value of multiple settings for the application
Pass a second arguement to return a default value if the setting is not set, defaults to null
ApplicationSettings::get(array [setting], array [default] = null);
Use this method to get all of the applications's settings as an array
ApplicationSettings::all()
To check if the application has a specific setting set, you can call
ApplicationSettings::has(string [setting]);
This will return true
if a value was found, false
if not.
All settings are saved automatically when ApplicationSettings::set();
is called.
To delete a setting, you can call
ApplicationSettings::delete(string [setting]);
There will be no return from this call.
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
This Laravel package is free software distributed under the terms of the MIT license. See LICENSE