This package uses spatie valuestore under the hood.
Combine Agency is a leading web development agency specializing in building innovative and high-performance web applications using modern technologies. Our experienced team of developers, designers, and project managers is dedicated to providing top-notch services tailored to the unique needs of our clients.
If you need assistance with your next project or would like to discuss a custom solution, please feel free to contact us or visit our website for more information about our services. Let's build something amazing together!
You can install the package via composer:
composer require combindma/laravel-option
You can publish the config file with:
php artisan vendor:publish --tag="laravel-option-config"
This is the contents of the published config file:
return [
/*
|--------------------------------------------------------------------------
| Default disk
|--------------------------------------------------------------------------
|
| This is the default disk that will be used to store the options file.
|
*/
'disk' => 'local',
/*
|--------------------------------------------------------------------------
| Default filename
|--------------------------------------------------------------------------
|
| This is the default filename for the options file.
|
*/
'filename' => 'options.json',
];
This package makes it easy to store and retrieve some loose values. Stored values are saved as a json file.
It can be used like this:
option()->put('key', 'value');
option()->get('key'); // Returns 'value'
option()->has('key'); // Returns true
// Specify a default value for when the specified key does not exist
option()->get('non existing key', 'default') // Returns 'default'
option()->put('anotherKey', 'anotherValue');
// Put multiple items in one go
option()->put(['ringo' => 'drums', 'paul' => 'bass']);
option()->all(); // Returns an array with all items
option()->forget('key'); // Removes the item
option()->flush(); // Empty the entire options
option()->flushStartingWith('somekey'); // remove all items whose keys start with "somekey"
option()->increment('number'); // option()->get('number') will return 1
option()->increment('number'); // option()->get('number') will return 2
option()->increment('number', 3); // option()->get('number') will return 5
// Option implements ArrayAccess
option()['key'] = 'value';
option()['key']; // Returns 'value'
isset(option()['key']); // Return true
unset(option()['key']); // Equivalent to removing the value
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.