shahghasiadil / laravel-env-validator
A Laravel package to validate environments variables configuration values and generate environments variables rules.
Requires
- php: ^7.3|^8.0
- illuminate/support: ^8.82|^9.0|^10.0
Requires (Dev)
- mockery/mockery: ^1.0
- orchestra/testbench: ^6.0|^7.0|^8.0
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-06-06 19:15:43 UTC
README
The laravel-env-validator
package provides a way to validate your .env
configuration values in a Laravel application.
Installation
-
Install via Composer:
composer require shahghasiadil/laravel-env-validator
-
Publish the Configuration:
php artisan vendor:publish --tag=config --provider="LaravelEnvValidator\LaravelEnvValidatorServiceProvider"
Usage
-
Generating Validation Rules from .env:
To generate validation rules based on your
.env
values:php artisan env:generate-rules
This will read your
.env
file, generate validation rules, and store them inconfig/env-validator.php
. -
Checking Env Validity:
To validate your current environment based on the generated rules:
php artisan env:vaildate
-
Middleware:
Ensure your environment is valid on every request by adding the middleware:
protected $middlewareAliases = [ 'ensureValidEnv' => \LaravelEnvValidator\Middlewares\EnsureValidEnv::class, ];
Add this to your
app/Http/Kernel.php
.Route::middleware('ensureValidEnv')->group(function () { // ... code });
Add middleware to your
routes/web.php
-
Customize Validation Rules:
To add or modify validation rules, edit the
config/env-validator.php
.
Configuration
All configuration for this package is stored in the env-validator.php
config file. It contains an array of validation rules corresponding to each key in your .env
file.
Changelog
For a detailed changelog, see the CHANGELOG.
Configs
If env changes aren't working please run the following command:
php artisan config:clear