Package Data | |
---|---|
Maintainer Username: | bradcornford |
Maintainer Contact: | me@bradleycornford.co.uk (Bradley Cornford) |
Package Create Date: | 2014-05-28 |
Package Last Update: | 2020-03-04 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-20 03:00:47 |
Package Statistics | |
---|---|
Total Downloads: | 1,044 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 13 |
Total Watchers: | 3 |
Total Forks: | 4 |
Total Open Issues: | 2 |
Think of Setter as an easy way to integrate Settings with Laravel, providing a variety of helpers to speed up the utilisation of application wide settings. These include:
Setting::set
Setting::get
Setting::forget
Setting::has
Setting::all
Setting::clear
Setting::expires
Begin by installing this package through Composer. Edit your project's composer.json
file to require cornford/setter
.
"require": {
"cornford/setter": "2.*"
}
Next, update Composer from the Terminal:
composer update
We now have to publish the packages assets with the following command:
php artisan vendor:publish --provider="Cornford\\Setter\\SettingServiceProvider"
We now have to migrate the package database table with the following command:
php artisan migrate
Once this operation completes, the next step is to add the service provider. Open config/app.php
, and add a new item to the providers array.
'Cornford\Setter\SettingServiceProvider',
The final step is to introduce the facade. Open config/app.php
, and add a new item to the aliases array.
'Setting' => 'Cornford\Setter\Facades\SettingFacade',
That's it! You're all set to go.
You can now configure Setter in a few simple steps. Open app/config/packages/cornford/setter/config.php
and update the options as needed.
cache
- Enable caching to improve performance by reducing database calls.tag
- A tag prefixed to all cache items, e.g. tag::.expiry
- The default expiry for cache items, e.g. 60.It's really as simple as using the Setter class in any Controller / Model / File you see fit with:
Setting::
This will give you access to
The set
method sets a setting via both a key and a value parameter in the database.
Setting::set('app.url', 'http://localhost');
The get
method gets a setting via a key parameter from the database, and a default value can be optionally passed if the setting doesn't exist.
If no default parameter is supplied, and an application configuration variable is present, this will be returned.
Setting::get('app.url', 'http://localhost');
Setting::get('app.url');
The forget
method removes a setting via a key parameter from the database.
Setting::forget('app.setting');
The has
method returns a true / false based on if a setting is present in the database via a key parameter.
This doesn't fall back to checking application configuration variables.
Setting::has('app.setting');
The all
method returns an array of key value pairs of settings from the database.
This doesn't fall back to return application configuration variables.
Setting::all();
The clear
method removes all settings from the database.
This doesn't fall back to removing application configuration variables.
Setting::clear();
The expires
method sets the cache expiry setting.
Can be false to not cache, true / 0 to cache indefinitely, an integer for minutes, or a datetime of when to expire.
Setting::expires(false);
The uncached
method ensures the next get request is requested from the database rather than the cache. It will also re-cache the item if one is found.
Setting::uncached();
Setting::uncached()->get('app.setting');
The cacheEnabled
method gets the current caching state returning a true / false based on the cache status, retuning the current Setter instance.
Setting::cacheEnabled();
The enableCache
method sets caching state to cache items, retuning the current Setter instance.
Setting::enableCache();
Setting::enableCache()->set('app.url', 'http://localhost');
The disableCache
method sets caching state to not cache items.
Setting::disableCache();
Setting::disableCache()->set('app.url', 'http://localhost');
The setCacheTag
method sets the currently caching prefix tag.
Setting::setCacheTag('tag:');
The getCacheTag
method gets the currently set caching prefix tag.
Setting::getCacheTag();
The cacheHas
method returns a true / false based on if a setting is present in the cache via a key parameter.
This doesn't fall back to checking application configuration variables.
Setting::cacheHas('app.setting');
The cacheForget
method removes a setting via a key parameter from the cache.
Setting::cacheForget('app.setting');
The cacheExpires
method sets the cache expiry setting.
Can be false to not cache, true / 0 to cache indefinitely, an integer for minutes, or a datetime of when to expire.
Setting::cacheExpires(false);
The cacheClear
method removes all settings from the cache.
This doesn't fall back to removing application configuration variables.
Setting::cacheClear();
Setter is open-sourced software licensed under the MIT license