combindma/laravel-option

A key-value storage for laravel

0.0.1 2024-07-29 16:36 UTC

This package is auto-updated.

Last update: 2024-10-29 17:12:25 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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.