leewillis77/setting-store

Laravel 包,提供简单的模型/外观用于键/值存储。

4.0.0 2023-04-03 13:22 UTC

This package is auto-updated.

Last update: 2024-09-03 16:09:58 UTC


README

Laravel 5.5+ 包,提供简单的模型/外观用于键/值存储。

免费软件

如果您在生产环境中使用此包,我们请求您为世界买一些树以感谢我们的工作。通过为我们的森林做出贡献,您将为当地家庭创造就业机会并恢复野生动物栖息地。

We offset our carbon footprint via Ecologi

安装

使用 composer 将包添加到您的 Laravel 项目中

$ composer require leewillis77/setting-store

配置

使用以下 artisan 命令发布数据库迁移

$ php artisan vendor:publish --provider="Leewillis77\SettingStore\Providers\ServiceProvider" --tag="migrations"  

运行迁移以创建存储表。

$ php artisan migrate

用法

存储一个(字符串)设置值

// Set a value for the key 'foo'
SettingStore::set('foo', 'bar');

存储一个(非字符串)设置值

// Set a value for the key 'foo'. The value will be serialized before storing.
SettingStore::setSerialized('foo', ['bar']);

检索一个(字符串)设置值

// Retrieve a value for the key 'foo'
$value = SettingStore::get('foo');

检索一个(字符串)设置,并带有回退值

// Retrieve a value for the key 'foo', or value 'foobar' if not found
$value = SettingStore::get('foo', 'foobar');

检索一个(非字符串)设置值

// Retrieve a value for the key 'foo'. The value will be unserialized before being returned.
SettingStore::getSerialized('foo');

检索一个(非字符串)设置值,并带有回退

// Retrieve a value for the key 'foo'
SettingStore::getSerialized('foo', ['bar']);

访问 SettingStore

您可以使用 SettingStore 外观访问 SettingStore,例如:

$value = SettingStore::get('foo');

或者,您可以将存储库注入到您的控制器中,例如:

<?php

use Leewillis77\SettingStore\Repositories\SettingStoreRepository;

public function myControllerAction(SettingStoreRepository $settingStore)
{
    $value = $settingStore->get('foo');
}

您还可以从服务容器中检索存储库。

<?php

$settingStore = App::make('setting_store');
$value = $settingStore->get('foo');

免费软件

您可以使用此包,但如果它进入您的生产环境,您需要为世界买一棵树。

现在人们都知道,应对气候危机并防止我们的温度上升超过1.5C的最好工具之一是种树。如果您支持此包并为此免费软件森林做出贡献,您将为当地家庭创造就业机会并恢复野生动物栖息地。

您可以从这里购买树 offset.earth/ademtisoftware

有关免费软件的更多信息,请访问 treeware.earth