Download the PHP package leeovery/laravel-settings without Composer
On this page you can find all versions of the php package leeovery/laravel-settings. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download leeovery/laravel-settings
More information about leeovery/laravel-settings
Files in leeovery/laravel-settings
Package laravel-settings
Short Description Laravel Settings - Package for handling user settings with file based defaults and DB custom values.
License MIT
Homepage https://github.com/leeovery/laravel-settings
Informations about the package laravel-settings
Laravel Settings
This package allows you to create one or many setting files which store default settings, but also expose an API to edit the settings, and store those edits in the DB. When the settings are fetched the custom values are merged into the defaults.
Most useful for user-based settings, but can be used for a multitude of other reasons.
Best to give a quick example...
Installation
You can install the package via composer:
Usage
Given a settings file called /config/settings-user-notifications.php
and with the following contents...
You can do this to fetch the settings:
As you can see, this will return all the above settings for user with the ID of 100.
Note that those settings won't be different from the defaults as at this point the user has not made any changes.
Lets change that now...
The line above calls set() and passes the key and value. That value is persisted in the DB for that user. So that we can do the following...
Returned data now equals all the default values EXCEPT for the nested key orders.general.email
where that will equal FALSE, as per the custom change above.
That's the most basic use-case...
But, you can do more...
Multiple Setting Files
You can setup multiple setting files in the config directory, just prepend the filename with settings-
(or whatever you configure in the package config file.
Eg:
/config/settings-user-privacy.php
/config/settings-social.php
/config/settings-user-account-access.php
Now you can get()
and set()
the settings from those files...
Value Object Based Values
You can use objects as the values in the settings file, like this:
Access Subsets Rather Than All Settings
Sometimes you only need a subset of settings. You can do that by specifiying the key with dot notation. Note the package will still fully key the results so that you can use the keys for setting.
Eg:
Given a setting file /config/settings-email-notifications.php
:
You can store a user edit like this:
And... you can access the deep status_change
subset like follows:
As you can see we fully key the results but only return the requested subset.
TODO
- [x] Can access subsets
- [ ] Caching to cut down on DB queries and general optimise
- [ ] Driver based approach to allow user to change default system and caching layer.
- [ ]
SettingStore
value validation
Testing
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
- Lee Overy
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.
All versions of laravel-settings with dependencies
illuminate/config Version ^8.0|^9.0
illuminate/database Version ^8.0|^9.0
illuminate/support Version ^8.0|^9.0
spatie/laravel-package-tools Version ^1.4.3
myclabs/deep-copy Version ^1.9
ext-json Version *