Installation
composer require worksome/envy --dev
Publish the config file:
php artisan vendor:publish --provider="Worksome\Envy\EnvyServiceProvider" --tag="config"
First Use Case
Run the sync command to generate/update .env and .env.example files:
php artisan envy:sync
.env.example to version control (never commit .env itself).Where to Look First
config/envy.php – Customize sync behavior (e.g., excluded keys, file paths).php artisan envy:sync (sync), php artisan envy:diff (compare changes).Onboarding New Developers
php artisan envy:sync in the project root to auto-generate .env.example with all config keys from config/ files..env.example via version control; developers run cp .env.example .env and populate values locally.post-clone hook in your repo (e.g., GitHub Actions) to auto-run envy:sync on fresh clones.Adding New Configuration
config/services.php (or any config file).php artisan envy:sync to update .env.example with the new key (default value: null).Environment-Specific Syncs
--env flag to sync only specific environments (e.g., php artisan envy:sync --env=staging).config/envy.php to define environment-specific templates (e.g., staging.env.example).CI/CD Integration
envy:sync in your CI pipeline (e.g., GitHub Actions) to validate .env.example is up-to-date before merging:
- name: Sync env files
run: php artisan envy:sync --validate
--dry-run to preview changes without modifying files..env.example during deploy prep to ensure consistency across servers.APP_KEY) from .env.example using config/envy.php:
'exclude' => [
'APP_KEY',
'DB_PASSWORD',
],
--path to sync env files for specific sub-projects:
php artisan envy:sync --path=packages/api
Sensitive Data Leaks
.env or exposing secrets in .env.example.APP_KEY, DB_PASSWORD) in config/envy.php:
'exclude' => ['APP_*', 'DB_*', 'AWS_*'],
php artisan envy:diff before committing .env.example to spot unintended exposures.Overwriting Local .env
envy:sync may overwrite existing .env if not careful.--dry-run first or exclude .env from sync:
'files' => [
'.env.example' => '.env.example',
// '.env' => '.env', // Commented out to avoid overwriting
],
Config File Changes Not Reflected
.env.example.php artisan config:clear) and run envy:sync again.Custom Config Parsing Issues
config/services.php with complex structures).custom option in config/envy.php to manually define keys:
'custom' => [
'SERVICE_X' => 'services.x.api_key',
],
-v flag for detailed logs:
php artisan envy:sync -v
php artisan envy:validate to check if .env.example matches your config.storage/logs/laravel.log for parsing issues.Custom Templates Override default templates by publishing assets:
php artisan vendor:publish --tag="envy-views"
Modify resources/views/vendor/envy/ to change file headers or formats.
Pre/Post-Sync Hooks Add logic before/after sync via service provider:
Envy::extend(function ($envy) {
$envy->beforeSync(function () {
// Pre-sync logic (e.g., backup .env)
});
});
Dynamic Key Generation
Use config/envy.php to dynamically generate keys from config:
'custom' => [
'QUEUE_CONNECTIONS' => function () {
return collect(config('queue.connections'))->keys()->implode(',');
},
],
Git Hooks
Automate syncs with a pre-commit hook to ensure .env.example is never outdated:
# .git/hooks/pre-commit
php artisan envy:validate || exit 1
How can I help you explore Laravel packages today?