dima-bzz / laravel-config-writer
Laravel provider to be able to rewrite configuration
Requires
- php: ^7.4|^8.0
- illuminate/config: ^7.0|^8.0
- illuminate/filesystem: ^7.0|^8.0
- illuminate/support: ^7.0|^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- mockery/mockery: ^1.3.3
- orchestra/testbench: ^5.0|^6.0
- phpunit/phpunit: ^9.3.3
README
Write to Laravel Config files and maintain file integrity.
This library adds the ability to write to configuration files.
You can rewrite array values inside a basic configuration file that returns a single array definition (like a Laravel config file) whilst maintaining the file integrity, leaving comments and advanced settings intact.
The following value types are supported for writing: strings, integers, booleans and arrays.
Support
This provider is designed to be used in Laravel from 7.4 and 8.0
version.
Setup
Install through composer:
composer require "dima-bzz/laravel-config-writer"
Set a filename to use as default in the .env
file:
...
CONFIG_WRITER=config
...
You can optionally publish the config file with:
php artisan vendor:publish --tag="config-writer"
After you've configured everything you should run the command artisan config:clear
or artisan config:cache
.
Introduction
The default is strict write mode. If you wish, you can change it in the configuration file:
... strict => false ...
Or through the Facade:
use DimaBzz\LaravelConfigWriter\Facades\ConfigWriter ... ConfigWriter::of([ 'item' => 'new value', 'nested.config.item' => 'value', 'arrayItem' => ['Single', 'Level', 'Array', 'Values'], 'numberItem' => 3, 'booleanItem' => true ]) ->strictMode(false) ->write(); ...
Usage the helper
This is the easiest way to write new data to the config file:
config_writer([ 'item' => 'new value', 'nested.config.item' => 'value', 'arrayItem' => ['Single', 'Level', 'Array', 'Values'], 'numberItem' => 3, 'booleanItem' => true ]);
Set another config file optional:
config_writer('config-writer', [ 'item' => 'new value', 'nested.config.item' => 'value', 'arrayItem' => ['Single', 'Level', 'Array', 'Values'], 'numberItem' => 3, 'booleanItem' => true ]);
Usage the Facade
You can write new data to the config file like this:
... ConfigWriter::write([ 'item' => 'new value', 'nested.config.item' => 'value', 'arrayItem' => ['Single', 'Level', 'Array', 'Values'], 'numberItem' => 3, 'booleanItem' => true ]); ...
Also, you can set certain parameters:
... ConfigWriter::of([ 'item' => 'new value', 'nested.config.item' => 'value', 'arrayItem' => ['Single', 'Level', 'Array', 'Values'], 'numberItem' => 3, 'booleanItem' => true ]) ->config('config-writer') ->strictMode(false) ->write(); ...
Events
DimaBzz\LaravelConfigWriter\Events\WriteSuccess
This event will be fired if writing to the configuration file was successful. It has the following public properties:
name
: configuration file name
Changelog
Please see CHANGELOG for more information on what has changed recently.
Security
If you discover any security related issues, please email dimabzz@gmail.com instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.