jubayed/laravel-config-writer

Laravel 提供器,用于重新编写配置

v8.0.0 2021-01-18 17:31 UTC

This package is auto-updated.

Last update: 2024-09-04 19:43:39 UTC


README

写入 Laravel 配置文件并维护文件完整性。

此库是 Laravel 使用的 Config 组件的扩展。它添加了写入配置文件的能力。

您可以在返回单个数组定义的基本配置文件(如 Laravel 配置文件)内部重写数组值,同时保持文件完整性,保留注释和高级设置。

支持以下值类型进行写入:字符串、整数、布尔值和单维度数组。

支持

此提供器设计用于从 8.x 版本的 Laravel 中使用。

设置

通过 composer 安装

composer require jubayed/laravel-config-writer dev-master

将以下内容添加到 app/config/app.php 中的 'providers' 键下

Jubayed\ConfigWriter\ConfigWriterServiceProvider::class,

用法

您可以像这样写入配置文件

Config::write('app.url', 'http://domain.com');

app('config')->write('app.url', 'http://domain.com');

外部 Laravel

Rewrite 类可以在任何地方使用。

$writeConfig = new Jubayed\ConfigWriter\DataWriter\Rewrite;
$writeConfig->toFile('path/to/config.php', [
    'item' => 'new value',
    'nested.config.item' => 'value',
    'arrayItem' => ['Single', 'Level', 'Array', 'Values'],
    'numberItem' => 3,
    'booleanItem' => true
]);