altairwn/laravel-options

从数据库加载全局选项

1.0.0 2024-03-28 09:52 UTC

This package is auto-updated.

Last update: 2024-09-28 10:48:12 UTC


README

Latest Version on Packagist Total Downloads Software License Build Status

数据库中的全局键值存储

安装

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

composer require appstract/laravel-options

发布、迁移

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

用法

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

// 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']);

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

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

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

use Option;

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

助手作为Blade指令可用

@option('someKey')

@option('someKey', 'Default value')

@optionExists('someKey')
    // Code
@endif

控制台

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

php artisan option:set {someKey} {someValue}

测试

$ composer test

贡献

欢迎贡献,感谢大家 :)

关于Appstract

Appstract 是来自荷兰的一个小型团队。我们为Web开发创建(开源)工具,并在 Medium 上撰写相关主题。您可以在 Twitter 上关注我们,为我们买一杯啤酒在Patreon上支持我们

许可

MIT 许可证 (MIT)。请参阅 许可文件 获取更多信息。