Looking to hire Laravel developers? Try LaraJobs

laravel-stack-env maintained by aaix

Description
A committed env layer for Laravel: .env.stack holds the defaults a project's stack dictates, the developer's .env only overrides them.
Author
Last update
2026/09/20 14:31 (dev-main)
License
Links
Downloads
0

Comments
comments powered by Disqus

Database driver, service hostnames, ports, queue and mail transport are the same for everyone working on a project — they follow from its stack, not from who checked it out. Put them in a committed .env.stack and a fresh clone runs without a single manual setting. Nobody's .env repeats them, .env.example stops listing them, and no config/*.php has to be touched.

Highest wins:

  1. Real environment variables — container, shell, CI
  2. .env — the developer's own file, not in version control
  3. .env.stack — committed, applies to everyone
  4. The env() fallback in config/*.php

Every key is decided on its own: .env overrides exactly the keys it defines and leaves the rest of .env.stack in place.

Setup

composer require aaix/laravel-stack-env

1. Register the loader in bootstrap/app.php. On the slim skeleton the file returns the builder expression directly, so assign it first:

$app = Application::configure(basePath: dirname(__DIR__))
    // ...
    ->create();

$app->singleton(
    \Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables::class,
    \Aaix\LaravelStackEnv\LoadEnvironmentVariables::class,
);

return $app;

On the classic skeleton $app already exists — put the same singleton() call next to the other bindings, above return $app;.

2. Create .env.stack in the project root and commit it. Make sure .gitignore does not swallow it: a .env* pattern would, and the layer only reaches your colleagues and CI once the file is in the repository.

DB_CONNECTION=mysql
DB_HOST=mysql
REDIS_HOST=redis
QUEUE_CONNECTION=redis

That is the whole integration. Check it with php artisan config:show database.

License

MIT.