cafesource / option
Laravel options
1.3.7
2022-06-08 08:01 UTC
Requires
- php: ^7.3 || ^8.0
- ext-json: *
- ext-mbstring: *
- ext-openssl: *
- cafesource/foundation: ^1.0
Provides
README
Installation
Require this package with composer using the following command:
composer require cafesource/option
Add the following class to the providers
array in config/app.php
:
Cafesource\Foundation\CafesourceServiceProvider::class, Cafesource\Option\OptionServiceProvider::class,
If you want to use the facade, add this to your facades in app.php:
'Option' => Cafesource\Option\Facades\Option::class,
Copy the package config to your local config with the publish command:
php artisan vendor:publish --provider="Cafesource\Option\OptionServiceProvider"
Autoload
You can save the settings with the option "autoload" so that they are loaded once when launching the program and you do not need to receive and execute a query when using it.
Usage
option('key', 'default'); // value option(['key','key2',...], 'default'); // options option()->exists('key'); // bool option()->update('key', 'value'); option()->whereIn('key', ['keys',...])->orderBy('key')->get(); option()->where('key','option')->where('type', 'array')->first(); option()->where('key','option')->limit(10)->groupBy('value')->get(); ...
use Cafesource\Option\Facades\Option; Option::first('key', 'default'); Option::get(['key','key2',...]) Option::update('key', 'value') Option::updateOrAdd('key', 'value') Option::remove('key') ...
Option type
You can save any data without conversion and receive it in its original form when used.
option()->add('key', [int|double|bool|array|object]); option('key'); // int,double,bool,array,object
example:
option()->updateOrAdd('example', ['cafesource','option']); option()->add('example2', true); option()->add('example3', Object); // Result option('example'); // ['cafesource','option'] option('example2')); // true option('example3'); // Object