larapack / config-writer
此包已被弃用且不再维护。未建议替代包。
在脚本中将更改保存到配置文件。
v1.0.1
2016-04-28 12:45 UTC
This package is auto-updated.
Last update: 2023-06-20 15:21:42 UTC
README
在脚本中将更改保存到配置文件。
安装
使用Composer安装:composer require larapack/config-writer 1.*。
使用它的外观
您可以使用我们的外观 Larapack\ConfigWriter\Facade 将 write-方法添加到默认的 Config-外观。
为此,您必须打开您的配置文件 config/app.php 并将 providers-部分的 'Config' => 'Illuminate\Support\Facades\Config::class', 替换为我们的外观 Larapack\ConfigWriter\Facade::class。然后它将看起来像 'Config' => 'Larapack\ConfigWriter\Facade::class',。
完成此操作后,您可以使用 Config::write($configFile, $changes),例如,通过以下方式更改您的应用程序URL:Config::write('app', ['url' => 'http://your-site.com'])。
使用仓库
您还可以使用仓库 Larapack\ConfigWriter\Repository,它的工作方式类似于模型。
示例
$config = new Larapack\ConfigWriter\Repository('app'); // loading the config from config/app.php
$config->set('debug', false); // set the config you wish
if ($config->get('url') == 'https://') // you can even get config from this
{
$config->set('debug', true);
}
$config->save(); // save those settings to the config file once done editing
如果您经常这样做,我建议在配置文件 config/app.php 的 alias-部分下添加别名 'ConfigWriter' => Larapack\ConfigWriter\Repository::class。