PHPackages                             syamsoul/laravel-set-env - 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. syamsoul/laravel-set-env

ActiveLaravel-package

syamsoul/laravel-set-env
========================

Easily update or insert Laravel environment variable with Artisan command

1.4.0(2mo ago)946.6k↓22.2%7[1 PRs](https://github.com/syamsoul/laravel-set-env/pulls)MITPHPPHP &gt;=8.0.0

Since Mar 21Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/syamsoul/laravel-set-env)[ Packagist](https://packagist.org/packages/syamsoul/laravel-set-env)[ RSS](/packages/syamsoul-laravel-set-env/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (16)Used By (0)

Laravel Environment Variable Setter
===================================

[](#laravel-environment-variable-setter)

[![Latest Version on Packagist](https://camo.githubusercontent.com/7f662fcea863743fe44d753aabf584a5b60cc8446cfe8e196e82c987c18f097a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7379616d736f756c2f6c61726176656c2d7365742d656e762e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/syamsoul/laravel-set-env)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![Total Downloads](https://camo.githubusercontent.com/33b3688cfec86ed2fdf1bb71ecf6cd52b4fa5dc41197396b80981c1f62186376/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7379616d736f756c2f6c61726176656c2d7365742d656e762e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/syamsoul/laravel-set-env)[![PHP Version](https://camo.githubusercontent.com/ba8a8f5681192e680386e80710cc1f15e2b68072fc8d7b2289a0fd8c8ae5310d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7379616d736f756c2f6c61726176656c2d7365742d656e762e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/syamsoul/laravel-set-env)

A Laravel package that enables programmatic modification of environment variables in your `.env` file. Simple, secure, and efficient way to manage your Laravel application's environment configuration.

✨ Features
----------

[](#-features)

- 🔐 Secure environment variable management
- 🚀 Simple and intuitive API
- 💻 Command-line interface support
- 📝 Support for comments in .env files
- 🎯 Precise variable positioning
- 🔄 Multiple file support (.env, .env.example, etc.)
- ⚡ Production-ready with safety checks

📋 Table of Contents
-------------------

[](#-table-of-contents)

- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
    - [Basic Setup](#basic-setup)
    - [Setting Environment Variables](#setting-environment-variables)
    - [Getting Environment Variables](#getting-environment-variables)
    - [Using Artisan Commands](#using-artisan-commands)
- [Production Usage](#production-usage)
- [Support](#support)
- [License](#license)

🔧 Requirements
--------------

[](#-requirements)

- Laravel 10.x or higher
- PHP 8.0 or higher

📦 Installation
--------------

[](#-installation)

You can install the package via Composer:

```
composer require syamsoul/laravel-set-env
```

🚀 Usage
-------

[](#-usage)

### Basic Setup

[](#basic-setup)

First, import the `Env` facade in your code:

```
use SoulDoit\SetEnv\Facades\Env;
```

### Setting Environment Variables

[](#setting-environment-variables)

There are multiple ways to set or update environment variables:

#### Using PHP Code

[](#using-php-code)

1. Basic usage:

```
// Set/update variable in .env file
Env::set("MY_APP_NAME", "My Laravel Application");

// Set/update variable in .env.example file
Env::envFile('.env.example')->set("MY_APP_NAME", "Localhost");
```

2. Add comments:

```
// Add a comment to explain the variable
Env::set("ENABLE_CLOCKWORK", false, "Enable or disable the clockwork debugging tools");
// Result in .env:
// ENABLE_CLOCKWORK=false #Enable or disable the clockwork debugging tools
```

3. Control variable positioning:

```
// Add/update a key after a specific key
Env::set("ENABLE_CLOCKWORK", false, afterKey: "APP_NAME");
// Result in .env:
// APP_NAME=MyApp
// ENABLE_CLOCKWORK=false
```

#### Using Artisan Commands

[](#using-artisan-commands)

1. Interactive mode:

```
php artisan souldoit:set-env
```

2. Direct mode:

```
php artisan souldoit:set-env "MY_APP_NAME=My Laravel Application"
```

3. Specify target env file:

```
php artisan souldoit:set-env "MY_APP_NAME=Localhost" -E .env.example
# or
php artisan souldoit:set-env "MY_APP_NAME=Localhost" --env_file=.env.example
```

### Getting Environment Variables

[](#getting-environment-variables)

Retrieve environment variable values using the `get` method:

```
$value = Env::get("MY_APP_NAME");
```

🛡️ Production Usage
-------------------

[](#️-production-usage)

When working in a production environment, you can use the `--force` flag to bypass confirmation prompts:

```
php artisan souldoit:set-env "MY_APP_NAME=Production App" --force
```

❤️ Support
----------

[](#️-support)

If you find this package helpful, consider supporting the development:

BNB (BSC) Donation Address:

```
0x364d8eA5E7a4ce97e89f7b2cb7198d6d5DFe0aCe

```

[![BNB Wallet QR Code](https://camo.githubusercontent.com/67c5326d8855725c2e2fe63a03bbb2dbd6efed10e1fda2c02c20af0a041a2a72/68747470733a2f2f696e666f2e736f756c646f69742e636f6d2f696d672f77616c6c65742d616464726573732d626e622d6273632e706e67)](https://camo.githubusercontent.com/67c5326d8855725c2e2fe63a03bbb2dbd6efed10e1fda2c02c20af0a041a2a72/68747470733a2f2f696e666f2e736f756c646f69742e636f6d2f696d672f77616c6c65742d616464726573732d626e622d6273632e706e67)

📄 License
---------

[](#-license)

This package is open-sourced software licensed under the [MIT License](LICENSE).

###  Health Score

53

—

FairBetter than 97% of packages

Maintenance86

Actively maintained with recent releases

Popularity38

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.6% 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 ~77 days

Recently: every ~148 days

Total

15

Last Release

74d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/605123f58f21c062a28a90d9db68fc30a26bc4b4016b35cb9787ae4e0c847a40?d=identicon)[syamsoul](/maintainers/syamsoul)

---

Top Contributors

[![syamsoul](https://avatars.githubusercontent.com/u/15118790?v=4)](https://github.com/syamsoul "syamsoul (31 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (2 commits)")[![marcogermani87](https://avatars.githubusercontent.com/u/998645?v=4)](https://github.com/marcogermani87 "marcogermani87 (1 commits)")[![skeemer](https://avatars.githubusercontent.com/u/864069?v=4)](https://github.com/skeemer "skeemer (1 commits)")

---

Tags

phplaravelartisansetenvcommandsouldoitsyamsoulprogramatically

### Embed Badge

![Health badge](/badges/syamsoul-laravel-set-env/health.svg)

```
[![Health](https://phpackages.com/badges/syamsoul-laravel-set-env/health.svg)](https://phpackages.com/packages/syamsoul-laravel-set-env)
```

###  Alternatives

[nunomaduro/laravel-console-menu

Laravel Console Menu is an output method for your Laravel/Laravel Zero commands.

815412.0k48](/packages/nunomaduro-laravel-console-menu)[nwidart/db-exporter

Export your database quickly and easily as a Laravel Migration and all the data as a Seeder class.

37839.1k](/packages/nwidart-db-exporter)[msztorc/laravel-env

Laravel env helper commands

7855.4k](/packages/msztorc-laravel-env)[elimuswift/db-exporter

Export your database quickly and easily as a Laravel Migration and all the data as a Seeder class.

364.7k](/packages/elimuswift-db-exporter)

PHPackages © 2026

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