combindma / laravel-option
A key-value storage for laravel
Fund package maintenance!
Combindma
Requires
- php: ^8.3
- illuminate/contracts: ^11.0
- spatie/laravel-package-tools: ^1.16
- spatie/valuestore: ^1.3
Requires (Dev)
- larastan/larastan: ^2.9.0
- laravel/pint: ^1.0
- nunomaduro/collision: ^8.0.0
- orchestra/testbench: ^9.0.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
README
This package uses spatie valuestore under the hood.
About Combind Agency
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!
Installation
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', ];
Usage
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
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.