PHPackages                             casperwilkes/laravel-environment\_detector2 - 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. casperwilkes/laravel-environment\_detector2

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

casperwilkes/laravel-environment\_detector2
===========================================

Builds appropriate .env configs, detects current laravel environment, uses corresponding .env. Requires Laravel Framework 7+.

1.0.0(5y ago)05MITPHPPHP ^7.2.5

Since Aug 31Pushed 5y ago1 watchersCompare

[ Source](https://github.com/casperwilkes/laravel-environment_detector2)[ Packagist](https://packagist.org/packages/casperwilkes/laravel-environment_detector2)[ RSS](/packages/casperwilkes-laravel-environment-detector2/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (4)Versions (2)Used By (0)

Laravel Environment Detector
============================

[](#laravel-environment-detector)

This is a simple environment detector made for working with multiple environments. This package should not need to be run very often, if at all after it's initial setup.

This is great for multiple environment setups.

Sometimes you don't want to save your `.env` files to your repository, in that case, add `.env*` to your `.gitignore` file.

Requirements
------------

[](#requirements)

This package is only available for Laravel Framework versions 7 and above. If you're looking for a package that works with 5 and 6 use [casperwilkes/environment\_detector](https://github.com/casperwilkes/laravel-environment_detector).

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

[](#installation)

There are a couple steps necessary to get the environment detector up and running.

### Composer

[](#composer)

To install the package through composer:

```
composer require casperwilkes/laravel-environment_detector2

```

### Laravel Publish

[](#laravel-publish)

Once you have installed through composer, you will want to publish the assets of the project

```
php artisan vendor:publish --tag=env-detector

```

This will publish the necessary bootstrap files and the config file.

The bootstrap file will be located at `./bootstrap/environment_detector.php`.

The config will be at `./config/environment_detector.php`

### Check Config

[](#check-config)

After you've published your config file, you'll want to update it with your environments, and perspective short names.

By default, there are some environments already setup.

```
'environments' => [
        'local' => 'local',
        'dev' => 'localhost',
        'qa' => '',
        'stage' => '',
        'prod' => '',
    ],
```

You can use whatever short names you want to describe your environment stage. This will create the shortname for the `.env` files.

For the environment name, you'll want the machines hostname. You can run `hostname` from the command line to get it.

For example, if you had 2 production environments called `prod_one`, and `prod_two`, you would use those for the short name, and use the machine's hostname for the environment field.

```
'environments' => [
        'local' => 'local',
        'dev' => 'localhost',
        'prod_one' => 'box284.gatorhost.com',
        'prod_two' => 'box246.redhost.com'
    ],
```

### Package Publish

[](#package-publish)

After you've published the vendor assets, you will want to publish the package.

To publish the package, run:

```
php artisan envdetector:publish

```

This will create the necessary environment files, and update your `App.php` to require the `environment_detector`. A backup of your previous version of `App.php` will be backed up in the same directory.

This will work it's way through your `environment_detector` config, and create a `.env` file for each environment found.

So, for our previous example, we'll get 4 different `.env` files.

- .env.local
- .env.dev
- .env.prod\_one
- .env.prod\_two

### Remove Package

[](#remove-package)

If for whatever reason you wish to remove the package, you can un-publish the package.

Run

```
php artisan envdetector:unpublish

```

This will remove the bootstrap files, and restore your app from the backup process.

**note:** If no backup is found, it will attempt to remove the require statement from `App.php`.

Usage
-----

[](#usage)

There are a couple usage options for both the envdetector commands.

### Publish

[](#publish)

For the publish command, there are 3 options:

- bootstrap (-b|--bootstrap)
    - this will backup `App.php` and add the require statement to bootstrap to load the correct `.env` file based on config.
- configs (-c|--configs)
    - This will create the necessary `.env.*` config files based on the config file. They will be copied from the original `.env` file.
- all (-a|--all), this will run all other options

**Notes**

For the bootstrap option, a backup copy of the original `App.php` is created and stored in the same directory. This will be used in case you've made previous changes to `App.php`, and you wish to revert back.

For the configs option, it will detect if a particular config already exists, and whether it should be overwritten. A prompt will appear asking for permission before assuming. If not configs are already setup, it will go ahead and create them. You can choose to overwrite all, or only some.

This is useful for when you've only added 1 or 2 new environments.

The original `.env.example` and `.env` will always remain untouched by this package.

### Un-publish

[](#un-publish)

For the un-publish command, there are 3 options:

- bootstrap (-b|--bootstrap)
    - This will restore the `App.php` file to it's original contents.
- configs (-c|--configs)
    - This will remove the config file, and all package created `.env.*` files.
- all (-a|--all), this will run all other options

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

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

2080d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2068298?v=4)[Casper Wilkes](/maintainers/casperwilkes)[@casperwilkes](https://github.com/casperwilkes)

---

Top Contributors

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

---

Tags

laraveldetectorenvironmentmultiplehostsconfigsmultiple environments

### Embed Badge

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

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

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[wnx/laravel-stats

Get insights about your Laravel Project

1.8k1.8M7](/packages/wnx-laravel-stats)[livewire/flux

The official UI component library for Livewire.

9385.0M86](/packages/livewire-flux)[glhd/conveyor-belt

14797.0k](/packages/glhd-conveyor-belt)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[sajadsdi/laravel-setting-pro

Easy settings management for laravel framework

1315.9k](/packages/sajadsdi-laravel-setting-pro)

PHPackages © 2026

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