laraveleg/options

You can create options, reuse them and rely on them at a later time. Inspired by the WordPress system and built on the Laravel framework

1.3.1 2021-09-14 20:48 UTC

This package is auto-updated.

Last update: 2021-10-14 20:57:01 UTC


README

Software License Travis Total Downloads

You can create options, reuse them and rely on them at a later time. Inspired by the WordPress system and built on the Laravel framework.

Install for laravel

composer require laraveleg/options

Install for lumen

composer require laraveleg/options

Register service provider

Go to bootstrap/app.php file and add the following line

$app->register(LaravelEG\LaravelOptions\LumenOptionsServiceProvider::class);

Migrate options table

php artisan migrate

Usage

You can manage options in a simple way by helpers.

Cache Mode

add_option

You can add an option through the following line :-

add_option($key, $value, $expiration);

$key: The option ID that you will use to fetch its value.

$value: Put the value of any type of data.

$expiration: Expiration date. This can be unused and saved all the time. Ex: add_option($key, $value).

get_option

Fetching value for a specific option :-

get_option($key, $default)

$key: The option ID. $default: You can specify a default value if the option is not found.

has_option

Make sure the option is there :-

has_option($key)

$key: The option ID.

remove_option

You can delete any option :-

remove_option($key)

$key: The option ID.

Eloquent Mode

You can put the settings to a specific element in a specific model.

Vendor publish

php artisan vendor:publish --provider="LaravelEG\LaravelOptions\LaravelOptionsServiceProvider"

Migrate options table

php artisan migrate

Set config

Go to laraveloptions.php file in configs directory

'eloquent_mode' => true, // Enable Eloquent Mode

Use for model

Add the trait in your specific model.

use LaravelEG\LaravelOptions\Traits\HasLaravelEGOptions;

class Unit extends Model
{
    use HasLaravelEGOptions;

add_option

You can add an option through the following line :-

$unit = Unit::find(1);
$unit->addOption($key, $value, $expiration);

$key: The option ID that you will use to fetch its value.

$value: Put the value of any type of data.

$expiration: Expiration date. This can be unused and saved all the time. Ex: add_option($key, $value).

get_option

Fetching value for a specific option :-

$unit = Unit::find(1);
$unit->getOption($key, $default)

$key: The option ID. $default: You can specify a default value if the option is not found.

has_option

Make sure the option is there :-

$unit = Unit::find(1);
$unit->hasOption($key)

$key: The option ID.

remove_option

You can delete any option :-

$unit = Unit::find(1);
$unit->removeOption($key)

$key: The option ID.

You an use this Trait in any model on your app.

Command-lines

Remove all options

php artisan laraveleg:options:remove-all

Remove all options on eloquent mode

Testing

Run the tests with:

vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security-related issues, please email komicho1996@gmail.com instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.