Download the PHP package justijndepover/laravel-settings without Composer
On this page you can find all versions of the php package justijndepover/laravel-settings. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download justijndepover/laravel-settings
More information about justijndepover/laravel-settings
Files in justijndepover/laravel-settings
Package laravel-settings
Short Description Store settings in your Laravel application
License MIT
Homepage https://github.com/justijndepover/laravel-settings
Informations about the package laravel-settings
Laravel Settings
Store settings in your Laravel application.
Installation
You can install the package with composer
After installation you can optionally publish your configuration file
configuration
This is the config file
If you chose the default database driver, you should publish the migration file and execute it
Usage
You have three different ways of interacting with the settings.
Use the global helper function
Inject the settings class with dependency injection
Use the global facade
all functionality is available with each method.
Examples
User settings
In addition to default settings, you can also use this package to store user settings.
Add the HasSettings
trait to your User model
After installing the trait, you get a settings
method on your user
Language specific settings
It's possible to store / access settings for specific locales.
Note on how this works
Caching
Whenever a read operation is executed, the package will check if the value is present in the cache. If it's not found, a read operation will be performed to the database (all values are fetched) and stored in the cache for other calls to consume.
This means that performing multiple reads (even with multiple keys) will only perform one database call.
If a write operation is performed, the cache is cleared. Resulting in a new read from database when a new settings is queried.
IMPORTANT This means the package uses the cache as it's main source, and falls back to the database otherwise. (which is good in most cases) If you change database values directly, you should clear the cache manually.
When working with serverless applications (e.g. AWS Lambda + Bref or Laravel Vapor), this could cause problems if you don't share the cache between the Lambda functions.
In this case you should either set your Laravel cache to something like Redis, or disable the cache feature in this package. To do this, publish the configuration file and set the cache_time
to 0
.
Clearing the cache
It's also possible to clear the cache programmatically:
User and locale settings
The default driver always stores a locale
and user_id
field in the database (defaults to null
).
Fetching data from the database will also query on these parameters.
To query something different than null
, you should chain the forUser
or forLocale
between the setting
and final method.
Security
If you find any security related issues, please open an issue or contact me directly at [email protected].
Contribution
If you wish to make any changes or improvements to the package, feel free to make a pull request.
License
The MIT License (MIT). Please see License File for more information.