PHPackages                             winter/laravel-config-writer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. winter/laravel-config-writer

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

winter/laravel-config-writer
============================

Utility to create and update Laravel config and .env files

v1.2.2(6mo ago)16350.1k↓29.1%108MITPHPPHP ^7.4.0 || ^8.0CI passing

Since Aug 1Pushed 6mo ago5 watchersCompare

[ Source](https://github.com/wintercms/laravel-config-writer)[ Packagist](https://packagist.org/packages/winter/laravel-config-writer)[ GitHub Sponsors](https://github.com/wintercms)[ Fund](https://opencollective.com/wintercms)[ RSS](/packages/winter-laravel-config-writer/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (9)Dependencies (3)Versions (10)Used By (8)

Laravel Config Writer
=====================

[](#laravel-config-writer)

[![Version](https://camo.githubusercontent.com/e1dd36480b0baf17ebba900ff1acd5665645ef1f652dbd1f585f36ce394812ac/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f77696e746572636d732f6c61726176656c2d636f6e6669672d7772697465723f736f72743d73656d766572267374796c653d666c61742d737175617265)](https://github.com/wintercms/laravel-config-writer/releases)[![Tests](https://camo.githubusercontent.com/4ba3b899da81e09ee37836e998d6b1679ab8053ec846dc2be6f01254a4cf08ff/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f77696e746572636d732f6c61726176656c2d636f6e6669672d7772697465722f74657374732e79616d6c3f266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/wintercms/laravel-config-writer/actions)[![License](https://camo.githubusercontent.com/adcd3d84305a313994821dc7e9fc91b474ced1af6cb69765ad710497e96f1e8e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f77696e746572636d732f6c61726176656c2d636f6e6669672d7772697465723f6c6162656c3d6f70656e253230736f75726365267374796c653d666c61742d737175617265)](https://packagist.org/packages/winter/laravel-config-writer)[![Discord](https://camo.githubusercontent.com/9ccde68755bc7666e40d293b454327a4315cb3ed8e7839dfaee5d6dc46fc5d01/68747470733a2f2f696d672e736869656c64732e696f2f646973636f72642f3831363835323531333638343139333238313f6c6162656c3d646973636f7264267374796c653d666c61742d737175617265)](https://discord.gg/D5MFSPH6Ux)

A utility to easily create and modify Laravel-style PHP configuration files and environment files whilst maintaining the formatting and comments contained within. This utility works by parsing the configuration files using the [PHP Parser library](https://github.com/nikic/php-parser) to convert the configuration into an abstract syntax tree, then carefully modifying the configuration values as required.

This library was originally written as part of the [Storm library](https://github.com/wintercms/storm) in [Winter CMS](https://wintercms.com), but has since been extracted and repurposed as a standalone library.

Installation
------------

[](#installation)

```
composer require winter/laravel-config-writer

```

Usage
-----

[](#usage)

### PHP array files

[](#php-array-files)

You can modify Laravel-style PHP configuration files - PHP files that return a single array - by using the `Winter\LaravelConfigWriter\ArrayFile` class. Use the `open` method to open an existing file for modification, or to create a new config file.

```
use Winter\LaravelConfigWriter\ArrayFile;

$config = ArrayFile::open(base_path('config/app.php'));
```

You can set values using the `set` method. This method can be used fluently, or can be called with a single key and value or an array of keys and values.

```
$config->set('name', 'Winter CMS');

$config
    ->set('locale', 'en_US')
    ->set('fallbackLocale', 'en');

$config->set([
    'trustedHosts' => true,
    'trustedProxies' => '*',
]);
```

You can also set deep values in an array value by specifying the key in dot notation, or as a nested array.

```
$config->set('connections.mysql.host', 'localhost');

$config->set([
    'connections' => [
        'sqlite' => [
            'database' => 'database.sqlite',
            'driver' => 'sqlite',
            'foreign_key_constraints' => true,
            'prefix' => '',
            'url' => null,
        ],
    ],
]);
```

To finalise all your changes, use the `write` method to write the changes to the open file.

```
$config->write();
```

If desired, you may also write the changes to another file altogether.

```
$config->write('path/to/newfile.php');
```

Or you can simply render the changes as a string.

```
$config->render();
```

#### Function calls as values

[](#function-calls-as-values)

Function calls can be added to your configuration file by using the `function` method. The first parameter of the `function` method defines the function to call, and the second parameter accepts an array of parameters to provide to the function.

```
$config->set('name', $config->function('env', ['APP_NAME', 'Winter CMS']));
```

#### Constants as values

[](#constants-as-values)

Constants can be added to your configuration file by using the `constant` method. The only parameter required is the name of the constant.

```
$config->set('foo.bar', $config->constant('My\Class::CONSTANT'));
```

#### Sorting the configuration file

[](#sorting-the-configuration-file)

You can sort the configuration keys alphabetically by using the `sort` method. This will sort all current configuration values.

```
$config->sort();
```

By default, this will sort the keys alphabetically in ascending order. To sort in the opposite direction, include the `ArrayFile::SORT_DESC` parameter.

```
$config->sort(ArrayFile::SORT_DESC);
```

### Environment files

[](#environment-files)

This utility library also allows manipulation of environment files, typically found as `.env` files in a project. The `Winter\LaravelConfigWriter\EnvFile::open()` method allows you to open or create an environment file for modification.

```
use Winter\LaravelConfigWriter\EnvFile;

$env = EnvFile::open(base_path('.env'));
```

You can set values using the `set` method. This method can be used fluently, or can be called with a single key and value or an array of keys and values.

```
$env->set('APP_NAME', 'Winter CMS');

$env
    ->set('APP_URL', 'https://wintercms.com')
    ->set('APP_ENV', 'production');

$env->set([
    'DB_CONNECTION' => 'sqlite',
    'DB_DATABASE' => 'database.sqlite',
]);
```

> **Note:** Arrays are not supported in environment files.

You can add an empty line into the environment file by using the `addEmptyLine` method. This allows you to separate groups of environment variables.

```
$env->set('FOO', 'bar');
$env->addEmptyLine();
$env->set('BAR', 'foo');
```

To finalise all your changes, use the `write` method to write the changes to the open file.

```
$env->write();
```

If desired, you may also write the changes to another file altogether.

```
$env->write(base_path('.env.local'));
```

Or you can simply render the changes as a string.

```
$env->render();
```

License
-------

[](#license)

This utility library is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

Security vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review our [security policy](https://github.com/wintercms/winter/security/policy) on how to report security vulnerabilities.

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance66

Regular maintenance activity

Popularity46

Moderate usage in the ecosystem

Community30

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 57.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~153 days

Recently: every ~110 days

Total

9

Last Release

206d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7253840?v=4)[Luke Towers](/maintainers/LukeTowers)[@LukeTowers](https://github.com/LukeTowers)

![](https://avatars.githubusercontent.com/u/15900351?v=4)[Ben Thomson](/maintainers/bennothommo)[@bennothommo](https://github.com/bennothommo)

---

Top Contributors

[![jaxwilko](https://avatars.githubusercontent.com/u/31214002?v=4)](https://github.com/jaxwilko "jaxwilko (22 commits)")[![bennothommo](https://avatars.githubusercontent.com/u/15900351?v=4)](https://github.com/bennothommo "bennothommo (7 commits)")[![LukeTowers](https://avatars.githubusercontent.com/u/7253840?v=4)](https://github.com/LukeTowers "LukeTowers (7 commits)")[![artengin](https://avatars.githubusercontent.com/u/152782500?v=4)](https://github.com/artengin "artengin (1 commits)")[![austinkregel](https://avatars.githubusercontent.com/u/5355937?v=4)](https://github.com/austinkregel "austinkregel (1 commits)")

---

Tags

confighacktoberfestlaravelphppluginwintercms

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/winter-laravel-config-writer/health.svg)

```
[![Health](https://phpackages.com/badges/winter-laravel-config-writer/health.svg)](https://phpackages.com/packages/winter-laravel-config-writer)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M345](/packages/psalm-plugin-laravel)[deptrac/deptrac

Deptrac is a static code analysis tool that helps to enforce rules for dependencies between software layers.

3.0k8.8M118](/packages/deptrac-deptrac)[roave/backward-compatibility-check

Tool to compare two revisions of a public API to check for BC breaks

6003.7M96](/packages/roave-backward-compatibility-check)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[coenjacobs/mozart

Composes all dependencies as a package inside a WordPress plugin

4814.0M25](/packages/coenjacobs-mozart)[v.chetkov/php-clean-architecture

PHP Clean Architecture

14661.1k](/packages/vchetkov-php-clean-architecture)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
