avris/dotenv
Tiny PHP dotenv loader for reading .env files and injecting variables into the environment, $_ENV, and $_SERVER. Supports common KEY=VALUE syntax, quotes, comments, and safe defaults to keep config out of code and VCS.
.env support via Illuminate\Support\Env, this package offers extended flexibility for custom paths, validation, and runtime overrides—critical for microservices, CLI tools, or dynamic configurations. It aligns with Laravel’s philosophy of environment-aware apps but fills gaps in native functionality (e.g., per-request overrides, non-file sources).Dotenv::validate()) and type safety, reducing runtime errors from malformed configs.env() helper with minimal code changes. Example:
// Replace:
$value = env('APP_DEBUG');
// With:
$value = Dotenv::get('APP_DEBUG');
vlucas/phpdotenv). However, dual usage (Laravel’s env() + Dotenv) risks configuration drift.DOTENV_PATH overrides)..env suffices, this package adds unnecessary complexity. Justification needed for features like runtime reloads or custom validation.spatie/laravel-env-editor)..env paths (e.g., per-tenant overrides)?env() helper?Dotenv::validate() add overhead in production?spatie/laravel-env-editor) with better support?Dotenv instances for dependency injection..env flexibility is critical..env files with runtime overrides..env system.env('KEY') vs. Dotenv::get('KEY')..env logic (e.g., vlucas/phpdotenv) with this package.env() usage (if fully migrated).bootstrap/app.php:
$dotenv = Dotenv::createImmutable(__DIR__.'/../');
$dotenv->load();
env('KEY') with config('app.key') or Dotenv::get('KEY') where needed.vlucas/phpdotenv (if used).Illuminate/Foundation (for bootstrap/app.php hooks).APP_ENV).composer.json:
"require": {
"avris/dotenv": "^1.0"
}
.env files (e.g., Dotenv::validate())..env files (if using custom paths).Dotenv::createImmutable()).Dotenv::validate()..env files.env() and Dotenv risks drift. Standardize early.config:cache for performance..env syntax/validation..env files.Dotenv::getAll() for troubleshooting..env management (e.g., "How to add a new env var").Dotenv-specific features (e.g., validate(), custom paths)..env as a backup..env files reduces I/O..env overrides)..env files per stage)..env consistency across instances.| Scenario | Impact | Mitigation |
|---|---|---|
Missing .env file |
App crashes (vs. Laravel’s fallback) | Use Dotenv::safeLoad() |
Malformed .env syntax |
Validation errors (clearer than Laravel’s) | CI/CD validation + Dotenv::validate() |
| Runtime config corruption | Inconsistent behavior | Disable runtime reloads in production |
| Package abandonment | Security/feature gaps | Fork or migrate to vlucas/phpdotenv |
| Naming collisions | env() vs. Dotenv conflicts |
Standardize on one approach early |
validate(), custom paths)..env management.Dotenv vs. env()..env-related issues.How can I help you explore Laravel packages today?