soandso/laravel-options

Laravel service for global storing key-value structure data

0.2.0 2022-03-25 19:58 UTC

This package is auto-updated.

Last update: 2024-05-26 01:12:09 UTC


README

GitHub GitHub Workflow Status (event) GitHub top language GitHub release (latest by date) Packagist PHP Version Support GitHub code size in bytes GitHub Release Date Codacy coverage

Laravel options

Laravel service for global storing in database key-value structure data

Requirements

This library only requires PHP >= 8.0

Setup

Add the library to your composer.json file in your project:

{
  "require": {
      "soandso/laravel-options": "0.*"
  }
}

Use composer to install the library:

$ php composer.phar install

You can also use composer on the command line to require and install Grouping:

$ php composer.phar require soandso/laravel-options

You should publish the migration with php artisan vendor:publish --provider="Soandso\LaravelOptions\OptionProvider"

Run php artisan migrate to migrate the table.

Usage

Facade

Set parameter value:

The parameter key must be unique to the Option entity Formats available for the parameter value - string, array

use Soandso\LaravelOptions\Option;

Option::set($key, $value);

The method returns true in case of successful setting of the parameter value or false in case of an error

Get parameter value:

Option::get($key);

If there is no parameter for the specified key, the method will return false

Check if the parameter with the given key exists

Option::exists($key);

Returns true or false depending on the result

Delete a parameter by its key

Option::destroyByKey($key);

Returns true if deletion was successful, false if deletion failed.

Helper function

With helper setOption() you can set options

setOption($key, $value)

helper getOption() will return the value of the option by its key

getOption($key)

Helper function existsOption() checks if the parameter with the given key exists

existsOption($key)

Function destroyOption deletes a parameter by its key

destroyOption($key)

Console

The command to delete parameters is available in the console.

 php artisan option:clear

This command will delete all data. You can restrict deletion by the date of creation or last update of the parameter

 php artisan option:clear <date>

Date must be in Y-m-d format. In this case, all parameters that are older than the specified date will be deleted.

License

Laravel option is licensed under the MIT License (https://github.com/appstract/laravel-options/blob/HEAD/LICENSE.md).