mjpakzad / laravel-settings
The laravel settings package let you save your settings in the database and access them easily.
README
The laravel settings package let you save your settings in the database and access them easily.
install
Add this package to your project using composer
composer require mjpakzad/laravel-settings
Publish the migration file
php artisan vendor:publish --provider="Mjpakzad\LaravelSettings\SettingServiceProvider"
Migrate the new migration to create settings table
php artisan migrate
Usage
Create a new setting
set_setting($key, $value, $group, $autoload)
You can group settings for example footer-settings
or seo
or anything else, default value of $group
is null
.
Also, you can autoload some settings to load in your AppServiceProvider, default value of $autoload
is false
.
examples
set_setting('site-name', 'Laravel settings')
set_setting('blog-title', 'My personal blog', 'blog', true)
Get a value by key
get_setting('site_name')
Get values by group
setting_group('blog')
Get autoload settings
setting_autoload($autoload)
default value of $autoload
is true
Also, you can bring all settings out to config.
setting_config()
This function save all settings as key-value pairs in config, you can filter settings by parameters like below:
setting_config($keys, $groups, $autoload)
All parameters have null
value.
Now, you can access them by config()
method:
config('settings')