PHPackages                             hampel/envroute - 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. hampel/envroute

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

hampel/envroute
===============

Package for customising the Laravel environment based on route

2.0.0(2y ago)018MITPHPPHP ^8.2

Since Feb 12Pushed 2y ago1 watchersCompare

[ Source](https://github.com/hampel/envroute)[ Packagist](https://packagist.org/packages/hampel/envroute)[ Docs](https://github.com/hampel/envroute)[ RSS](/packages/hampel-envroute/feed)WikiDiscussions 1.2 Synced 1mo ago

READMEChangelogDependencies (1)Versions (13)Used By (0)

EnvRoute for Laravel
====================

[](#envroute-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b2e6abbe04e30a460ef609e6a3eabd7a061f99483a7cb92019c17f1f01383dc2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68616d70656c2f656e76726f7574652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hampel/envroute)[![Total Downloads](https://camo.githubusercontent.com/5f4e1cdc1b5e390a503a417d76bcc0d66ee303c4f9324ec393f61e2bf4861b96/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68616d70656c2f656e76726f7574652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hampel/alerts)[![Open Issues](https://camo.githubusercontent.com/ad427d697896921f06f9a9c060976e48c680d4c4b2ab31cebdc6808f92121f38/68747470733a2f2f696d672e736869656c64732e696f2f6269746275636b65742f6973737565732f68616d70656c2f656e76726f7574652e7376673f7374796c653d666c61742d737175617265)](https://bitbucket.org/hampel/envroute/issues)[![License](https://camo.githubusercontent.com/3a9a97b76c897293500257b9df879b0dd97aac8093380713f8a3294befbfc5e5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f68616d70656c2f656e76726f7574652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hampel/envroute)

By [Simon Hampel](mailto:simon@hampelgroup.com).

This package provides route-based environment detection and configuration for Laravel v5.x|v6.x|v7.x - it is intended for use in development environments for testing packages using Laravel as a test harness.

This is not just for developing Laravel specific packages - any type of package can use this environment for testing, Laravel just provides a convenient test harness for us, making it easier to exercise our packages while developing.

About
-----

[](#about)

This package works on the assumption that you have multiple independent packages (that may or may not depend on Laravel) which you develop locally and you have a single Laravel framework installation which you use as a test harness for exercising your packages above and beyond what you might do in unit tests.

It does not matter where your packages are installed - I have started placing mine in the `/packages` directory under the Laravel root folder, but the EnvRoute configuration for each package can be set to handle any location.

The other assumption is that you want to be able to autoload a specific package to work on, without autoloading other unrelated packages you might be working on.

This was one limitation of the Laravel 4.x Workbench in that it always autoloaded every package in the Workbench, which sometimes lead to inconsistent or undesirable behaviour - particularly when you have packages depending on different versions of the same package.

For example, let's say you develop PackageA, which has a dependency on PackageX v1.1.\*, and you also develop PackageB, which also has a dependency on PackageX, but requires v2.0.\*

In Workbench, you would run `composer update` to generate the autoload file for any dependencies on each package. However, because all vendor autoload files from all packages are autoloaded, what happens is that PackageX v1.1.\* is autoloaded first (because this is the first one it finds when searching), and then PackageX v2.0.\* is never made available to your packageB when testing. The only way around this is to delete the `vendor` folder from PackageA before testing PackageB, which is a pain - especially if you forget and subtle package dependency differences give you unexpected results which take you time to diagnose.

EnvRoute solves this by allowing you to selectively autoload only the dependencies you need and then set a custom environment configuration to test in.

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

[](#installation)

The recommended way of installing the EnvRoute package is through [Composer](http://getcomposer.org):

```
:::bash
composer require "hampel/envroute"

```

Or manually define it in your `composer.json`

```
:::json
{
    "require": {
        "hampel/envroute": "^1.0"
    }
}

```

Run Composer to update the new requirement.

```
:::bash
$ composer update

```

You will need to swap out the default Http Kernel with the one provided by this package by editing the app bootstrap file. Edit `bootstrap/app.php`, remove or comment out the singleton loading for `App\Http\Kernel` and replace it with `EnvRoute\Http\Kernel`.

```
:::php
//$app->singleton(
//	Illuminate\Contracts\Http\Kernel::class,
//	App\Http\Kernel::class
//);

$app->singleton(
	Illuminate\Contracts\Http\Kernel::class,
	EnvRoute\Http\Kernel::class
);

```

The EnvRoute version of the Http Kernel extends the default Http Kernel, so any future updates to the base framework should not cause any problems.

**Note** - DO NOT change the namespace for your Laravel Framework - this package assumes that the base classes will be found in the default `App` namespace.

Next, publish the EnvRoute configuration:

```
:::bash
$ php artisan vendor:publish --provider="EnvRoute\EnvRouteServiceProvider"

```

Follow the instructions in the usage section for how to configure EnvRoute to work with your packages.

Usage
-----

[](#usage)

### Routes

[](#routes)

The EnvRoute package changes the default environment detection mechanism.

The intention is to create a route prefix for each package you are developing and then you can configure a unique environment just for that package. For example - you could create a unique database connection for each package.

Start by creating a route group for your package in the `routes/web.php` file:

```
:::php
Route::prefix('test')->group(function() {

	Route::get('/', function () {
		// exercise your package at /test
	});

	Route::get('foo', function () {
		// exercise your package at /test/foo
	});
});

```

Next, for our `test` route prefix, create a `.env` file suffixed by the name of the route prefix - in this example, we would call our .env file `.env.test`. You can then configure this .env file with any package unique settings which will be loaded whenever you visit a URL starting with `/test`.

**Important** - you must also set the APP\_ENV variable within your .env file to match the route prefix.

```
APP_NAME="My Test Package"
APP_ENV=test

```

This is important, since it is the APP\_ENV variable which will determine which packages are autoloaded by the EnvRoute service provider.

### Autoloading

[](#autoloading)

To set up autoloading of your package files, edit the `config/envroute.php`, configuration file to add the path to your package. The list of packages is an array, with each key corresponding to the environment route we set up in the previous step.

```
:::php
'packages' => [

	'test' => [
		'path' => base_path() . '/packages/test',
	],

],

```

In the above example, we have a package named 'test' (this doesn't have to correspond to the actual package name we are testing - but it does have to correspond to the name of the route prefix). We define our route prefix for testing as `/test` and a corresponding environment file `.env.test` and an APP\_ENV value of `test`.

Our configuration tells the autoloader that the 'test' package is being developed in the folder `/packages/test` and once we have run `composer update` in this folder to load all package dependencies and create the autoload file, our package is ready for testing.

### Service Providers

[](#service-providers)

If your package has Laravel service providers which need to be loaded, add them to a `providers` array key in the configuration. For example:

```
:::php
'packages' => [

	'test' => [
		'path' => base_path() . '/packages/test',

		'providers' => [
			'Test\TestServiceProvider',
		],
	],
],

```

Note that this isn't restricted to just your packages own service providers - any other service providers your package (or test harness) depends on which aren't already loaded by the base framework should be added to the providers array.

### Aliases

[](#aliases)

If your package has an alias (facade) which need to be loaded, add them to a `aliases` array key in the configuration. For example:

```
:::php
'packages' => [

	'test' => [
		'path' => base_path() . '/packages/test',

		'providers' => [
			'Test\TestServiceProvider',
		],

		'aliases' => [
			'Test' => 'Test\Facades\Test',
		]
	],
],

```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity83

Battle-tested with a long release history

 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

Every ~306 days

Recently: every ~355 days

Total

12

Last Release

741d ago

Major Versions

0.4.0 → 1.0.02019-03-27

1.4.0 → 2.0.02024-05-08

PHP version history (3 changes)0.1.0PHP &gt;=5.4.0

0.4.0PHP &gt;=5.5.0

2.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/b2e02745af0cfa73e5f00eb8faf965a13296351e62f4802cc76a148cdbc95dbd?d=identicon)[hampel](/maintainers/hampel)

---

Top Contributors

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

---

Tags

environmentlaravelroutelaravelenvironmentroute

### Embed Badge

![Health badge](/badges/hampel-envroute/health.svg)

```
[![Health](https://phpackages.com/badges/hampel-envroute/health.svg)](https://phpackages.com/packages/hampel-envroute)
```

###  Alternatives

[msztorc/laravel-env

Laravel env helper commands

7855.4k](/packages/msztorc-laravel-env)[sven/env-providers

Load Laravel service providers based on your application's environment.

769.7k](/packages/sven-env-providers)[interaction-design-foundation/laravel-geoip

Support for multiple Geographical Location services.

17221.0k3](/packages/interaction-design-foundation-laravel-geoip)[harmonic/laravel-envcoder

:description

414.1k](/packages/harmonic-laravel-envcoder)

PHPackages © 2026

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