macsidigital/laravel-setting

2.1.0 2020-09-08 15:17 UTC

This package is auto-updated.

Last update: 2024-09-04 10:30:10 UTC


README

数据库中的配置

Header Image

tests badge version badge downloads badge

一个设置包,用于将设置保存到数据库并通过配置访问。

支持我们

我们在创建开源包上投入了大量资金,如果您通过使用这些包的产品获得收入,我们将不胜感激赞助

安装

此包可在Laravel 6.0或更高版本中使用。

您可以通过composer安装此包

composer require macsidigital/laravel-setting

您必须使用以下命令发布迁移

php artisan vendor:publish --tag="setting-migrations"

使用方法

您可以这样保存组和设置

$group = Group::create([
    'identifier' => "test",
    'name' => "Test Settings",
    'description' => "Test Settings and other things"
]);
$item = Item::make(['key' => 'mailchimp', 'name' => 'Mailchimp Key', 'description' => 'Your Mailchimp API key so we can enable communication with your Mailchimp account']);
$group->items()->save($item);

由于我们使用了Eloquent,您可以使用任何Eloquent函数。例如,执行以下操作以检索设置组。

Group::where('identifier', 'membership')->first();

我们通过常规关系方式链接到项目

foreach(Group::where('identifier', 'membership')->first()->items){
	// do something
}

自动加载

有一个自动加载字段,如果设置,将自动将设置加载到配置中

$group = Group::create([
    'identifier' => "test",
    'name' => "Test Settings",
    'description' => "Test Settings and other things",
    'autoload' => true
]);
$item = Item::make(['key' => 'mailchimp.api', 'name' => 'Mailchimp Key', 'description' => 'Your Mailchimp API key so we can enable communication with your Mailchimp account', 'autoload' => true]);
$group->items()->save($item);

// Access with
config('test.mailchimp.api');

这将在设置服务提供程序启动时自动加载。

测试

composer test

变更日志

请参阅CHANGELOG以获取有关最近更改的更多信息。

贡献

请参阅CONTRIBUTING以获取详细信息。

安全

如果您发现任何与安全相关的问题,请通过电子邮件info@macsi.co.uk联系,而不是使用问题跟踪器。

致谢

许可

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