syamsoul/laravel-set-env
Programmatically set, update, and read Laravel .env variables with a simple facade and CLI. Supports comments, precise placement, and multiple env files (.env, .env.example). Includes production safety checks for secure environment configuration management.
Architecture Fit
The syamsoul/laravel-set-env package is a lightweight, Laravel-specific solution for dynamic .env file management, aligning well with Laravel’s configuration-driven architecture. Its focus on programmatic environment variable manipulation (with support for comments, positioning, and multiple files) fits seamlessly into Laravel’s ecosystem, particularly for:
.env, .env.production, .env.local).Key Fit Criteria:
Integration Feasibility
.env modifications (e.g., feature toggles, environment-specific overrides)..env version control policies (e.g., Git-tracked .env files), as the package modifies files directly..env parsing logic (e.g., encrypted .env files, non-standard formats).Technical Risk
.env files, which may fail in shared hosting or containerized environments (e.g., Docker with read-only filesystems).--force flag or configure storage_path() for writable directories..env simultaneously.Cache facade for temporary overrides..env modifications in shared environments (e.g., multi-tenant SaaS).Gate::before()) or use API tokens..env at runtime..env file handling (e.g., file_put_contents) suffices.Key Questions
.env changes a core requirement (e.g., feature flags) or a nice-to-have?config_cache invalidation, environment variables in .env.example)?.env files managed in CI/CD (e.g., Git-ignored vs. template-based)?.env files in production)?config() helper or env() function suffice for most use cases?.env writes (e.g., secret leaks)?Stack Fit
.env management (e.g., SaaS platforms, microservices with environment-specific configs)..env files are deployed dynamically..env workflows (e.g., .env.example only).Migration Path
.env management (e.g., manual edits, scripts, third-party tools).composer require syamsoul/laravel-set-env
Env::set('APP_DEBUG', env('APP_ENV') !== 'production');
php artisan souldoit:set-env "DB_HOST=production-db" --force
.env edits with the package (e.g., CI/CD pipelines).Env::set())..env modification scripts.Compatibility
composer why-not syamsoul/laravel-set-env.file extension for .env file operations (standard in Laravel)..env files; may need adjustments for Docker/read-only filesystems.Sequencing
.env.local, .env.testing).APP_DEBUG, APP_URL)..env files (use --force cautiously).DB_PASSWORD, APP_KEY)—consider environment variable injection instead..env updates.Maintenance
.env updates eliminate typos in .env files.php artisan souldoit:set-env --log)..env formatting (comments, positioning).composer.json and Artisan command set.Support
chmod 644 .env)..env (e.g., unescaped quotes).php artisan souldoit:set-env --help for CLI options.Env::get('VAR') to verify values..env changes (e.g., git checkout .env).Scaling
.env values in config() or Cache::remember().Failure Modes
| Scenario | Impact | Mitigation |
|---|---|---|
.env file locked/read-only |
Runtime errors | Use --force or configure writable path. |
Concurrent .env modifications |
Corrupted .env file |
Implement file locking or use Cache. |
| Package breaks with Laravel 13.x | Integration failure | Pin to a stable version (^1.4). |
| Sensitive data leaked via CLI | Security breach | Restrict Artisan commands to admins. |
Ramp-Up
Env::set() vs. config() usage..env (e.g., feature flags) vs. static configs.after_script in GitLab)..env files (e.g., git stash before updates).syamsoul/laravel-set-env to phpstorm.meta.php for autocomplete..env changes to a centralized audit system (e.g., ELK, Datadog).Key Metrics to Track
.env changes automated via the package..env modification failures (e.g., permissions, syntax).Env::set() in high-traffic endpoints.How can I help you explore Laravel packages today?