Laravel Drift is a pre-deploy environment validation and configuration drift detection tool. It acts as a gatekeeper, comparing your .env against .env.example and running safety checks before your application boots.
- No-Boot Validation: Runs without booting the Laravel application container for maximum safety and speed.
- Drift Detection: Identifies missing keys in
.envor orphan keys in.env.example. - Safety Gates: Prevents common deployment disasters like
APP_DEBUG=truein production or using placeholderAPP_KEYvalues. - Extensible Rules: Easily add your own custom validation rules.
- CI/CD Integration: Simple exit code contracts to block failing builds.
You can install the package via composer:
composer require fr3on/laravel-driftYou can publish the config file with:
php artisan vendor:publish --tag="drift-config"Run the drift check:
php artisan drift:checkIn your CI/CD pipeline, use the --strict flag to treat warnings as errors:
php artisan drift:check --strict| Rule | Description | Status |
|---|---|---|
AppDebugRule |
Ensures APP_DEBUG is false when APP_ENV is production. |
Fail |
AppKeyRule |
Validates presence, length, and ensures no placeholder values are used. | Fail |
CompletenessRule |
Compares .env keys against .env.example. |
Fail/Warn |
QueueDriverRule |
Warns if QUEUE_CONNECTION=sync is used in production. |
Warn |
You can create custom rules by implementing the Fr3on\Drift\Contracts\DriftRule interface:
use Fr3on\Drift\Contracts\DriftRule;
use Fr3on\Drift\EnvMap;
use Fr3on\Drift\RuleResult;
class MyCustomRule implements DriftRule
{
public function check(EnvMap $env, EnvMap $example): RuleResult
{
if ($env->missing('MY_REQUIRED_KEY')) {
return RuleResult::fail('MY_REQUIRED_KEY is missing!');
}
return RuleResult::pass();
}
}Register your rules in config/drift.php.
The MIT License (MIT). Please see License File for more information.