emresari89/laravel-options

从数据库加载的全局选项

v1.1.2 2022-07-13 10:43 UTC

This package is auto-updated.

Last update: 2024-09-13 15:20:26 UTC


README

Latest Version on Packagist Total Downloads Software License Build Status

全局键值存储在数据库中

安装

要开始使用laravel-options,请使用Composer将包添加到项目的依赖中

composer require emresari89/laravel-options

发布,迁移

在您的项目中运行 php artisan vendor:publish --provider="Emresari\Options\OptionsServiceProvider",此包的所有文件都将发布。对于此包,它只包含迁移。运行 php artisan migrate 来迁移表。现在您的数据库中将有一个名为 options 的表。

使用方法

使用 option() 辅助函数,我们可以获取和设置选项

// Get all options 
options();

// Get option by id
optionID($id);

// Get option
option('someKey');

// Get option, with a default fallback value if the key doesn't exist
option('someKey', 'Some default value if the key is not found');

// Set option
option(['someKey' => 'someValue']);

// Set option with type (type 1 default)
option_type(['someKey' => 'someValue'],null,2);

// Remove option
option()->remove('someKey');

// Check the option exists
option_exists('someKey');

如果您想检查选项是否存在,可以使用外观

use Option;

$check = Option::exists('someKey');

控制台

也可以在控制台中设置选项

php artisan option:set {someKey} {someValue}

测试

$ composer test

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件