hungnm1518 / config-writer
在脚本中保存配置文件更改。
1.1.1
2024-04-24 18:14 UTC
Requires (Dev)
- laravel/framework: ^7.0|^8.0|^9.0|^10.0|^11.0
This package is auto-updated.
Last update: 2024-09-24 19:10:24 UTC
README
在脚本中保存配置文件更改。
安装
使用 Composer 安装 composer require hungnm1518/config-writer
。
使用它的外观
您可以使用我们的外观 HungNM\ConfigWriter\Facade
将 write
方法添加到默认的 Config
外观。
为此,您必须打开您的配置文件 config/app.php
,并在 providers
部分下用我们的外观 HungNM\ConfigWriter\Facade::class
替换 'Config' => 'Illuminate\Support\Facades\Config::class',
。然后它看起来像 'Config' => 'HungNM\ConfigWriter\Facade::class',
。
完成此操作后,您可以使用 Config::write($configFile, $changes)
,例如,通过 Config::write('app', ['url' => 'http://your-site.com'])
修改您的应用程序 URL。
使用仓库
您还可以使用仓库 HungNM\ConfigWriter\Repository
,它的工作方式有点像模型。
示例
$config = new HungNM\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' => HungNM\ConfigWriter\Repository::class
。