shah-newaz/laravel-config-writer

Laravel 提供商,用于重写配置

v4.0.0 2020-10-11 19:31 UTC

This package is auto-updated.

Last update: 2024-09-12 04:26:30 UTC


README

注意 ⚠

此包是从daftspunk/laravel-config-writer 分支的,并修复了原始包中的错误。

写入 Laravel 配置文件并保持文件完整性。

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

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

支持的写入值类型包括:字符串、整数、布尔值和一维数组。

支持

此提供者旨在从 5.4 版本开始在 Laravel 中使用。

设置

通过 composer 安装

composer require "altynbek07/laravel-config-writer"

使用 Laravel 5.4 吗?

如果您使用 Laravel 5.4 进行安装,您需要在 app/config/app.php 中的 'providers' 键下添加此内容。
否则,如果您使用 5.5,这将自动完成,归功于包自动发现。

October\Rain\Config\ServiceProvider::class,

Lumen 情况

将此内容添加到 bootstrap/app.php 中的 'service providers' 部分声明中

$app->register(October\Rain\Config\ServiceProvider::class);

用法

您可以这样写入配置文件

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

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

外部 Laravel

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

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