Laravel 5.5+ package to provide a simple model / facade for key/value storage.
If you use this package in production, we ask that you buy the world some trees to thank us for our work. By contributing to our forest you’ll be creating employment for local families and restoring wildlife habitats.
Add the package to your Laravel project using composer:
$ composer require leewillis77/setting-store
Publish the database migration using the following artisan command:
$ php artisan vendor:publish --provider="Leewillis77\SettingStore\Providers\ServiceProvider" --tag="migrations"
Run the migration to create the storage table.
$ php artisan migrate
// Set a value for the key 'foo'
SettingStore::set('foo', 'bar');
// Set a value for the key 'foo'. The value will be serialized before storing.
SettingStore::setSerialized('foo', ['bar']);
// Retrieve a value for the key 'foo'
$value = SettingStore::get('foo');
// Retrieve a value for the key 'foo', or value 'foobar' if not found
$value = SettingStore::get('foo', 'foobar');
// Retrieve a value for the key 'foo'. The value will be unserialized before being returned.
SettingStore::getSerialized('foo');
// Retrieve a value for the key 'foo'
SettingStore::getSerialized('foo', ['bar']);
You can access the SettingStore using the SettingStore
facade, e.g.
$value = SettingStore::get('foo');
Alternatively, you can inject the repository into your controllers, e.g.
<?php
use Leewillis77\SettingStore\Repositories\SettingStoreRepository;
public function myControllerAction(SettingStoreRepository $settingStore)
{
$value = $settingStore->get('foo');
}
You can also retrieve the repository from the service container.
<?php
$settingStore = App::make('setting_store');
$value = $settingStore->get('foo');
You're free to use this package, but if it makes it to your production environment you are required to buy the world a tree.
It’s now common knowledge that one of the best tools to tackle the climate crisis and keep our temperatures from rising above 1.5C is to plant trees. If you support this package and contribute to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.
You can buy trees here offset.earth/ademtisoftware
Read more about Treeware at treeware.earth