Package Data | |
---|---|
Maintainer Username: | ahmedash95 |
Maintainer Contact: | edv.krucas@gmail.com (Edvinas Kručas) |
Package Create Date: | 2017-01-22 |
Package Last Update: | 2017-01-23 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-11 15:01:59 |
Package Statistics | |
---|---|
Total Downloads: | 15 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Persistent settings package for Laravel 5.
composer require ahmedash95/laravle-settings
Add following lines to app/config/app.php
ServiceProvider array
Krucas\Settings\Providers\SettingsServiceProvider::class,
Alias array
'Settings' => Krucas\Settings\Facades\Settings::class
If you want to edit default config file, just publish it to your app folder.
php artisan vendor:publish --provider="Krucas\Settings\Providers\SettingsServiceProvider" --tag="config"
Package comes with several configuration options.
| Setting | Description |
| --- | --- |
| default
| Setting repository driver. |
| cache
| Enable or disable setting cache. |
| encryption
| Enable or disable setting value encryption. |
| events
| Enable or disable event firing. |
| repositories
| Config of all repositories which can be used. |
| key_generator
| Key generator class. |
| context_serializer
| Context serializer class. |
| value_serializer
| Value serializer class. |
| override
| Allows you to override values in Laravel config array. |
To use database driver you have to create table in your database. Package provides default table migration, to create it you need to execute artisan command:
$ php artisan settings:table
Set setting value.
Settings::set($key, $value = null);
Get setting value, default value is returned when no value found.
Settings::get($key, $default = null);
Determine if setting exists.
Settings::has($key);
Forget setting value from repository.
Settings::forget($key);
Setting values may be used in certain context. Context can be set using method context()
.
Settings::context(new Context(['user' => 1]));
Context is reset after call of one these methods set
, get
, has
, forget
.
Example how to use settings for different contexts.
$userContext1 = new Context(['user' => 1]);
$userContext2 = new Context(['user' => 2]);
Settings::context($userContext1)->set('key', 'value1');
Settings::context($userContext2)->set('key', 'value2');
// retrieve settings
$userValue1 = Settings::context($userContext1)->get('key'); // value1
$userValue2 = Settings::context($userContext2)->get('key'); // value2
Resolve settings service instance.
settings();
Set setting value.
settings([$key => $value]);
Set setting value for a context.
settings([$key => $value], new Context(['user' => 1]));
Get setting value, default value is returned when no value found.
settings($key, $default = null);
Getting value for a context.
settings($key, $default, new Context(['user' => 1]));
Events gets fired if this is not disabled via config (enabled by default).
Fired before checking if value is present in repository.
| Parameter | Type | Parameter description | | --- | --- | --- | | $key | string | Setting key. | | $context | null or Context | Setting context. |
Fired after checking if value is present in repository.
| Parameter | Type | Parameter description |
| --- | --- | --- |
| $key | string | Setting key. |
| $status | bool | If setting exists true
is passed, otherwise false
|
| $context | null or Context | Setting context. |
Fired before retrieving value from repository.
| Parameter | Type | Parameter description | | --- | --- | --- | | $key | string | Setting key. | | $default | mixed | Default setting value. | | $context | null or Context | Setting context. |
Fired after retrieving value from repository.
| Parameter | Type | Parameter description | | --- | --- | --- | | $key | string | Setting key. | | $value | mixed | Retrieved setting value. | | $default | mixed | Default setting value. | | $context | null or Context | Setting context. |
Fired before setting value to repository.
| Parameter | Type | Parameter description | | --- | --- | --- | | $key | string | Setting key. | | $value | mixed | Setting value to be set. | | $context | null or Context | Setting context. |
Fired after setting value to repository.
| Parameter | Type | Parameter description | | --- | --- | --- | | $key | string | Setting key. | | $value | mixed | Setting value to be set. | | $context | null or Context | Setting context. |
Fired before forgetting value.
| Parameter | Type | Parameter description | | --- | --- | --- | | $key | string | Setting key. | | $context | null or Context | Setting context. |
Fired after forgetting value.
| Parameter | Type | Parameter description | | --- | --- | --- | | $key | string | Setting key. | | $context | null or Context | Setting context. |