PHPackages                             fvfvfvfv/laravel-envguard - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [DevOps &amp; Deployment](/categories/devops)
4. /
5. fvfvfvfv/laravel-envguard

ActiveLibrary[DevOps &amp; Deployment](/categories/devops)

fvfvfvfv/laravel-envguard
=========================

Typed, validated, documented environment schema for Laravel — replaces .env.example with real tooling.

v1.0.0(2mo ago)00MITPHPPHP ^8.2

Since Mar 5Pushed 2mo agoCompare

[ Source](https://github.com/fvfvfvfv/laravel-envguard)[ Packagist](https://packagist.org/packages/fvfvfvfv/laravel-envguard)[ Docs](https://github.com/fvfvfvfv/laravel-envguard)[ RSS](/packages/fvfvfvfv-laravel-envguard/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

Laravel EnvGuard
================

[](#laravel-envguard)

Typed, validated, documented environment variable schemas for Laravel. Replaces the convention of committing a `.env.example` with real tooling: a schema file that defines types, validation rules, required/optional status, and documentation for every environment variable your application uses.

Why this exists
---------------

[](#why-this-exists)

The standard Laravel workflow is to commit a `.env.example` file with placeholder values and tell developers to copy it to `.env` and fill it in. This has a few problems that get worse at scale:

- **No types.** Nothing prevents a string going into `DB_PORT` or a garbage value going into `APP_URL`.
- **No validation.** You find out a variable is missing or wrong when the application breaks, not when you deploy.
- **No documentation.** Comments in `.env.example` drift or disappear. New team members have no idea what half the variables do or whether they are required.
- **No environment awareness.** Some variables are required in production but not locally. `.env.example` cannot express that.
- **No diffing.** You cannot easily see what your local env is missing compared to production, or what someone added to production without documenting.
- **No CI gate.** Nothing stops a deployment to an environment where a required variable is missing.

EnvGuard solves all of this with a single `.env.schema.php` file that you commit to version control. The schema is the source of truth. The `.env.example` becomes a generated artifact.

Features
--------

[](#features)

- **Typed schema** — define each variable as `string`, `integer`, `float`, `boolean`, `enum`, `url`, or `email`
- **Fluent builder** — a readable API for documenting requirements, defaults, validation rules, and warnings
- **Environment-specific requirements** — a variable can be optional locally but required in production
- **Sensitive value masking** — secrets are automatically redacted in diff output
- **Remote environment readers** — compare or validate environments via local files, SSH, Laravel Forge, or Laravel Cloud
- **Seven Artisan commands** — validate, diff, check, generate, audit, drift, init
- **CI/CD gate** — fail your pipeline if a deployment environment is missing required variables

Installation
------------

[](#installation)

```
composer require fvfvfvfv/laravel-envguard
```

The service provider is auto-discovered. Publish the config file if you want to customize it:

```
php artisan vendor:publish --tag=envguard-config
```

Quick start
-----------

[](#quick-start)

**1. Generate a schema from your existing `.env.example`:**

```
php artisan env:init
```

This creates `.env.schema.php` at your project root. If `.env.example` exists, EnvGuard parses it and creates an entry for each variable. If it does not exist, it generates a schema covering all standard Laravel variables.

**2. Customize the schema:**

Open `.env.schema.php` and annotate each variable:

```
return [
    'APP_KEY' => EnvVar::string()
        ->required()
        ->sensitive()
        ->description('Application encryption key — generate with: php artisan key:generate'),

    'APP_ENV' => EnvVar::enum(['local', 'staging', 'production'])
        ->required()
        ->description('Deployment environment'),

    'DB_PORT' => EnvVar::integer()
        ->optional()
        ->min(1)
        ->max(65535)
        ->default(3306),

    'STRIPE_SECRET' => EnvVar::string()
        ->requiredIn(['production', 'staging'])
        ->sensitive()
        ->validatedBy('starts_with:sk_')
        ->description('Stripe secret key'),
];
```

**3. Validate your local environment:**

```
php artisan env:validate
```

**4. Commit the schema file.** It replaces `.env.example` as the canonical reference for what your application needs.

---

Defining a schema
-----------------

[](#defining-a-schema)

The schema file lives at `.env.schema.php` (configurable) and must return an associative array mapping variable names to `EnvVar` instances.

```
