hebrahimzadeh / laravel-config-writer
Laravel 提供器,可用于重写配置
v2.0.2
2021-08-08 14:54 UTC
Requires
- php: ^7.4|^8.0
Requires (Dev)
- orchestra/testbench: ^6.19
This package is auto-updated.
Last update: 2024-09-08 21:53:59 UTC
README
写入 Laravel 配置文件并维护文件完整性。
该库是 Laravel 使用的 Config 组件的扩展。它增加了写入配置文件的能力。
您可以在返回单个数组定义的基本配置文件中重写数组值(如 Laravel 配置文件),同时保持文件完整性,保留注释和高级设置。
支持以下值类型进行写入:字符串、整数、布尔值和单维数组。
支持
此提供器旨在从 5.4
版本的 Laravel 中使用。
还支持 php:7.4
和 laravel 8
设置
通过 composer 安装
composer require "daftspunk/laravel-config-writer"
将以下内容添加到 app/config/app.php
中的 'providers' 键下
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 ]);
致谢
此软件包使用的是您自己分叉的版本。