Polyscope - The agent-first dev environment for Laravel

Laravel Env Keys Checker

Laravel Env Keys Checker stats

Downloads
43
Stars
16
Open Issues
1
Forks
3

View on GitHub →

check if all the keys are available in all the .env files.

Check if all the keys are available across all the .env files.

This package checks if all the keys are available across all the .env files. This package is useful when you have multiple .env files and want to ensure all the keys are available across all the .env files.

With a team of developers, it is possible that some developers might forget to add the keys they used in their .env file to the .env.example file or the other way around.

Table of Contents

Features

  • Check if all the keys are available across all the .env files.
  • Add the missing keys to the .env files automatically (configurable) considering the line numbers and empty lines.
  • Check if the .env and other provided files are present in .gitignore, so that they are not committed to git by mistake.
  • Sync all the available keys by line across all the .env files. Referencing the master .env file. (Configurable, default is .env)

Installation

You can install the package via composer:

composer require msamgan/laravel-env-keys-checker --dev

To configure this package, you can add environment variables to your .env files. See the config file for details. Please make sure that you refresh the config cache after adding/updating the environment variables. php artisan config:cache

If you prefer, you can also publish the config file with:

php artisan vendor:publish --tag="env-keys-checker-config"

Usage

To check if all the keys are available across all the .env files.

php artisan env:keys-check

Options

--auto-add: This option will add the missing keys to the .env files automatically. The possible values are ask, auto, and none. The default value is ask.

--no-progress: This option will disable the progress bar.

--no-display: This option will disable all output.

To check if the .env and other provided files are present in .gitignore.

php artisan env:in-git-ignore

To sync all the available keys by line across all the .env files.

php artisan env:sync-keys

In Test

You can also use this package in your test cases to make sure the required feature is working as expected.

To check if all the keys are available across all the .env files.

Add the following code to your test case.

Make sure to add --auto-add=none to override the default configuration.

it('tests that the .env key are same across all .env files.', function () {
$this->artisan('env:keys-check --auto-add=none')->assertExitCode(0);
});

To check if the .env and other provided files are present in .gitignore.

Add the following code to your test case.

it('tests that the .env and other provided files are present in .gitignore.', function () {
$this->artisan('env:in-git-ignore')->assertExitCode(0);
});

Configuration

You can configure the package by publishing the configuration file.

# config/env-keys-checker.php
# List of all the .env files to ignore while checking the env keys
# .env key: KEYS_CHECKER_IGNORE_FILES (coma separated string)
 
'ignore_files' => [],
# config/env-keys-checker.php
# List of all the .env keys to ignore while checking the env keys
# .env key: KEYS_CHECKER_IGNORE_KEYS (coma separated string)
 
'ignore_keys' => [],
# config/env-keys-checker.php
# strategy to add the missing keys to the .env file
# ask: will ask the user to add the missing keys
# auto: will add the missing keys automatically
# none: will not add the missing keys
# .env key: KEYS_CHECKER_AUTO_ADD (string)
 
'auto_add' => 'ask',
# config/env-keys-checker.php
# List of all the .env.* files to be checked if they
# are present in the .gitignore file.
# .env key: KEYS_CHECKER_GITIGNORE_FILES (coma separated string)
 
'gitignore_files' => ['.env'],
# Master .env file to be used for syncing the keys
'master_env' => env('MASTER_ENV', '.env'),

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

msamgan photo

Seasoned Software Engineer with 10+ years of experience

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Msamgan Laravel Env Keys Checker Related Articles

Check Env Variables Across All .env Files image

Check Env Variables Across All .env Files

Read article
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
Honeybadger logo

Honeybadger

Simple developer-focused application monitoring for Laravel. Error tracking, log management, uptime monitoring, status pages, and more!

Honeybadger
The Certification of Competence for Laravel logo

The Certification of Competence for Laravel

A community-driven, proctored assessment across 4 levels designed to validate real-world Laravel knowledge, from Junior to mastery-level Artisan. Official Vue.js, Official Nuxt, Angular, React, JS certifications also available.

The Certification of Competence for Laravel
Curotec logo

Curotec

World class Laravel experts with GenAI dev skills. LATAM-based, embedded engineers that ship fast, communicate clearly, and elevate your product. No bloat, no BS.

Curotec
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Securing Laravel logo

Securing Laravel

The essential security resource for Laravel devs, covering everything you need to keep your apps secure. Sign up to receive weekly security tips and monthly in depth articles, diving deep into security concepts you need to know!

Securing Laravel