Download the PHP package rudnev/laravel-settings without Composer
On this page you can find all versions of the php package rudnev/laravel-settings. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rudnev/laravel-settings
More information about rudnev/laravel-settings
Files in rudnev/laravel-settings
Package laravel-settings
Short Description Persistent settings for Laravel Framework
License MIT
Homepage https://github.com/rudnev/laravel-settings
Informations about the package laravel-settings
Laravel Settings
Persistent settings for Laravel Framework
- Easy to Use
- App Settings + User Settings (Scopes)
- Events
- Cache
- Extendable Settings Manager
- Laravel Octane compatible
Requirements
- PHP 7.1 or higher
- Laravel 5.5 or higher
Basic usage
Retrieve and store data using the global settings
function:
You can also use the Settings
facade:
And if you prefer contracts, you can use Method dependency injection:
Getting started
Installation
API
Scopes
Translation
Cache
Events
Custom store
Installation
You can install the package via composer:
Publish the migration with:
After the migration has been published you can create the settings table by running the migrations:
API
Check the value
Determine if an item exists in the settings store.
Get the value
Retrieve an item from the settings store by key.
Get multiple values
Retrieve multiple items from the settings store by key. Items not found in the settings store will have a null value.
Get all values
Get all the settings items.
Set the value
Store an item in the settings store.
Set multiple values
Store multiple items in the settings store.
Remove the value
Remove an item from the settings store.
Remove multiple values
Remove multiple items from the settings store.
Remove all values
Remove all items from the settings store.
Dot Notation
You can use dot syntax to indicate the item depth:
Scopes
If you want to have settings for your model you can use scope
method:
But instead, it's better to use the Rudnev\Settings\Traits\HasSettings
trait, for example:
Now you can use settings
property to set and get values:
Also, settings
method provides direct access to the settings store (but model state will not be updated):
To set the default settings define $settingsConfig
property as array with default
key:
And if you want specify the store from config/settings.php
, use store
option:
In addition to the scopes for models, you can freely create scopes for your application settings, for example:
Translation
I suggest using the built-in laravel methods to translate any keys, names and descriptions. You can use this approach for most laravel packages, there is no need to store translations within different database tables when you can do this in one place.
For example, create a file resources/lang/en/settings.php
:
And get translated strings:
Cache
Cache is enabled by default, you can change this in your config/settings.php
file.
To clear the cache you can run the following Artisan command:
Note: this command does not actually delete cache entries, it only invalidates them by changing the prefix for keys. If you are using settings for models, the cache can grow quickly. For this reason, it is recommended to use drivers that support eviction policies, such as
redis
, or use the commandphp artisan cache:clear
to completely clear the cache.
Events
Events are triggered if this is not disabled via config (enabled by default).
Event | Description |
---|---|
\Rudnev\Settings\Events\PropertyWritten | Fired after the value is written to the store. |
\Rudnev\Settings\Events\PropertyReceived | Fired after the value is retrieved from the store. |
\Rudnev\Settings\Events\PropertyMissed | Fired if the item not found or is not set. |
\Rudnev\Settings\Events\PropertyRemoved | Fired after the item is removed from the store. |
\Rudnev\Settings\Events\AllSettingsReceived | Fired after retrieving all items from the store. |
\Rudnev\Settings\Events\AllSettingsRemoved | Fired after removing all items from the store. |
Custom Store
To create your own store, you must use the extend
method on the SettingsManager
, which is used to bind a custom driver resolver to the manager, but first you need implement the
StoreContract:
After that, to register a new settings driver named "mongo", you would do the following:
The first argument passed to the extend method is the name of the driver. This will correspond to your driver option in the config/settings.php
configuration file. The second argument is a Closure that should return an Rudnev\Settings\Repository
instance. The Closure will be passed an $app
instance, which is an instance of Illuminate\Foundation\Application
and a service container.
The call to Settings::extend
could be done in the boot
method of the default App\Providers\AppServiceProvider
that ships with fresh Laravel applications, or you may create your own service provider to house the extension.
Finally, you can access your store as follows:
Credits
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-settings with dependencies
ext-json Version *
illuminate/contracts Version ^5.5|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
illuminate/database Version ^5.5|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
illuminate/events Version ^5.5|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
illuminate/support Version ^5.5|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0