angus-dv/laravel-setting is a Laravel package for laravel persistent settings..
It currently has 0 GitHub stars and 17 downloads on Packagist.
Install it with composer require angus-dv/laravel-setting.
Discover more Laravel packages by angus-dv
or browse all Laravel packages to compare alternatives.
Last updated
This package makes it easy to store and retrieve some loose values. Stored values are saved as a json file.
Supoort Laravel 8 and PHP 8
It can be used like this:
settings('key'); // Returns 'value'
settings()->get('key'); // Returns 'value'
settings()->has('key'); // Returns true
// Specify a default value for when the specified key does not exist
settings()->get('non existing key', 'default') // Returns 'default'
settings()->put('anotherKey', 'anotherValue');
settings('anotherKey', 'anotherValue');
settings(['anotherKey'=> 'anotherValue']);
// Put multiple items in one go
settings()->put(['ringo' => 'drums', 'paul' => 'bass']);
settings()->all(); // Returns an array with all items
settings()->forget('key'); // Removes the item
settings()->flush(); // Empty the entire valuestore
settings()->flushStartingWith('somekey'); // remove all items whose keys start with "somekey"
settings()->increment('number'); // settings()->get('number') will return 1
settings()->increment('number'); // settings()->get('number') will return 2
settings()->increment('number', 3); // settings()->get('number') will return 5
You can install the package via composer:
composer require angus-dv/laravel-setting
and for register service provider:
'providers' => [
AngusDV\LaravelSetting\LaravelSettingServiceProvider::class,
],
and run migration to create the database table:
php artisan migrate
You can call the following methods on the settings()
/**
* Put a value in the store.
*
* @param string|array $name
* @param string|int|null $value
*
* @return $this
*/
public function put($name, $value = null)
/**
* Get a value from the store.
*
* @param string $name
*
* @return null|string
*/
public function get(string $name)
/*
* Determine if the store has a value for the given name.
*/
public function has(string $name) : bool
/**
* Get all values from the store.
*
* @return array
*/
public function all() : array
/**
* Get all values from the store which keys start with the given string.
*
* @param string $startingWith
*
* @return array
*/
public function allStartingWith(string $startingWith = '') : array
/**
* Forget a value from the store.
*
* @param string $key
*
* @return $this
*/
public function forget(string $key)
/**
* Flush all values from the store.
*
* @return $this
*/
public function flush()
/**
* Flush all values from the store which keys start with the specified value.
*
* @param string $startingWith
*
* @return $this
*/
public function flushStartingWith(string $startingWith)
/**
* Get and forget a value from the store.
*
* @param string $name
*
* @return null|string
*/
public function pull(string $name)
/**
* Increment a value from the store.
*
* @param string $name
* @param int $by
*
* @return int|null|string
*/
public function increment(string $name, int $by = 1)
/**
* Decrement a value from the store.
*
* @param string $name
* @param int $by
*
* @return int|null|string
*/
public function decrement(string $name, int $by = 1)
/**
* Push a new value into an array.
*
* @param string $name
* @param $pushValue
*
* @return $this
*/
public function push(string $name, $pushValue)
/**
* Prepend a new value into an array.
*
* @param string $name
* @param $prependValue
*
* @return $this
*/
public function prepend(string $name, $prependValue)
/**
* Count elements.
*
* @return int
*/
public function count()
$ composer test
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT)