laraveleg/options
Composer 安装命令:
composer require 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
README 文档
README
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
Traitin 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.
统计信息
- 总下载量: 60
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-08-23