PHPackages                             ejetar/laravel-environment - 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. ejetar/laravel-environment

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

ejetar/laravel-environment
==========================

📂 Load a custom .env file according to your environment.

0.1.0(6y ago)5239MITPHPPHP &gt;=5.4.0

Since Nov 7Pushed 5y ago1 watchersCompare

[ Source](https://github.com/ejetar/laravel-environment)[ Packagist](https://packagist.org/packages/ejetar/laravel-environment)[ Docs](https://ejetar.com/projects/laravel-environment)[ RSS](/packages/ejetar-laravel-environment/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Laravel Environment
===================

[](#laravel-environment)

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

[](#table-of-contents)

- [About](#about)
- [How it works](#how-it-works)
- [Get started](#get-started)
    - [Examples](#examples)
        - [From system environment variable method](#from-system-environment-variable-method)
            - [First example](#first-example)
            - [Second example](#second-example)
            - [Third example](#third-example)
        - [From file method](#from-file-method)
            - [First example](#first-example-1)
        - [From custom method](#from-custom-method)
            - [First example](#first-example-2)
- [Installation](#installation)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [License](#license)

About
-----

[](#about)

Laravel Environment is a library designed to be used in conjunction with Laravel. It enables the user to **load a different .env file from the original**. The coolest thing about this library is that it **provides different methods** for you to do this.

There are currently 3 methods:

```
\Ejetar\LaravelEnvironment\LaravelEnvironment::fromSystemEnvironmentVariable($system_environment_variable_name, $default_value = 'local')
//Loads an environment file according to the value of a system environment variable
```

```
\Ejetar\LaravelEnvironment\LaravelEnvironment::fromFile($filename)
//Loads an environment file explicitly, stating the file path
```

```
\Ejetar\LaravelEnvironment\LaravelEnvironment::fromCustomMethod(Callable $callable)
//Enables the user to enter a custom method for loading the environment file
```

How it works
------------

[](#how-it-works)

To use this library is very simple, just call Laravel Environment before `return $app;` in the `bootstrap/app.php` file:

```
...

\Ejetar\LaravelEnvironment\LaravelEnvironment::fromSystemEnvironmentVariable('MYAPP_ENV');

return $app;
```

Get started
-----------

[](#get-started)

### Examples

[](#examples)

#### From system environment variable method

[](#from-system-environment-variable-method)

##### First example

[](#first-example)

We assume in this example that the system environment variable MYAPP\_ENV exists and has the value 'production'.

```
\Ejetar\LaravelEnvironment\LaravelEnvironment::fromSystemEnvironmentVariable('MYAPP_ENV');
//Will load the environment file .env.production
```

##### Second example

[](#second-example)

We assume in this example that the system environment variable MYAPP\_ENV does not exist.

```
\Ejetar\LaravelEnvironment\LaravelEnvironment::fromSystemEnvironmentVariable('MYAPP_ENV');
//Will load the .env.local environment file. When the system environment variable does not exist, then it takes $default_value.
//By default $default_value is set to 'local'.
```

##### Third example

[](#third-example)

We assume in this example that the system environment variable MYAPP\_ENV does not exist, and $default\_value will be 'acme'.

```
\Ejetar\LaravelEnvironment\LaravelEnvironment::fromSystemEnvironmentVariable('MYAPP_ENV', 'acme');
//Will load the .env.acme environment file. When the system environment variable does not exist, then it takes $default_value.
```

#### From file method

[](#from-file-method)

##### First example

[](#first-example-1)

```
\Ejetar\LaravelEnvironment::fromFile('.env.local');
//Load the .env.local file explicitly
```

#### From custom method

[](#from-custom-method)

##### First example

[](#first-example-2)

Loading the server IP-based environment file:

```
\Ejetar\LaravelEnvironment\LaravelEnvironment::fromCustomMethod(function(){
  switch($_SERVER['SERVER_ADDR']) {
    case '1.2.3.4':
      return '.env.local';
      break;
    case '5.6.7.8':
      return '.env.production';
      break;
    default:
      return '.env.other';
  }
});
```

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

[](#installation)

`composer require ejetar/laravel-environment`

Changelog
---------

[](#changelog)

Nothing for now...

Contributing
------------

[](#contributing)

Contribute to this wonderful project, it will be a pleasure to have you with us. Let's help the free software community. You are invited to incorporate new features, make corrections, report bugs, and any other form of support. Don't forget to star in this repository! 😀

License
-------

[](#license)

This library is a open-source software licensed under the MIT license.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

2378d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/781358602863d7536e95494388bda4d9f53175fdf5029d9db7b45d4eabef10e9?d=identicon)[ejetar](/maintainers/ejetar)

---

Top Contributors

[![ggirardi1](https://avatars.githubusercontent.com/u/2306117?v=4)](https://github.com/ggirardi1 "ggirardi1 (4 commits)")

---

Tags

devdevelopmentdotenvenvenvironmentlaravellocalphpproductionphplaraveldevenvironmentdevelopmentenvdotenvlocalproduction

### Embed Badge

![Health badge](/badges/ejetar-laravel-environment/health.svg)

```
[![Health](https://phpackages.com/badges/ejetar-laravel-environment/health.svg)](https://phpackages.com/packages/ejetar-laravel-environment)
```

###  Alternatives

[vlucas/phpdotenv

Loads environment variables from `.env` to `getenv()`, `$\_ENV` and `$\_SERVER` automagically.

13.5k602.4M5.4k](/packages/vlucas-phpdotenv)

PHPackages © 2026

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