teun / laravel-environment-config-validator
Validate Laravel environment variables against configurable rules.
Package info
github.com/teunvanderploeg/laravel-environment-config-validator
pkg:composer/teun/laravel-environment-config-validator
v1.0.0
2026-02-16 09:15 UTC
Requires
- php: ^8.2
- illuminate/console: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
- illuminate/validation: ^10.0|^11.0|^12.0
Requires (Dev)
- laravel/pint: ^1.13
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpunit/phpunit: ^10.5|^11.0
README
Validate Laravel environment variables against rules you define in config.
Installation
composer require teun/laravel-environment-config-validator
Publish the config file:
php artisan vendor:publish --tag=env-validator-config
Configuration
Set rules in config/env-validator.php:
return [ 'preset' => 'standard', // standard | strict | custom | your-own-preset-key 'env_file' => null, // null = runtime env, or set '.env.testing' 'presets' => [ 'standard' => [ // built-in default Laravel-oriented rules ], 'strict' => [ // built-in stricter production-focused rules ], 'my-team' => [ 'APP_ENV' => ['required', 'in:staging,production'], 'DB_PASSWORD' => ['required', 'string'], ], ], // Overrides selected preset keys. If preset=custom, this is the full ruleset. 'rules' => [ 'APP_ENV' => ['required', 'in:local,staging,production'], ], 'check_env_example' => true, ];
Usage
Run validation:
php artisan env:validate
Override preset at runtime:
php artisan env:validate --preset=strict
Validate a specific file (for example .env.testing):
php artisan env:validate --env-file=.env.testing
Machine-readable output:
php artisan env:validate --json
Fail CI when .env.example is missing required keys:
php artisan env:validate --strict-example
CI example
php artisan env:validate --strict-example
Use this command in your deployment or CI pipeline to fail early on invalid environment config.
Testing
composer test
License
MIT