PHPackages                             zeyad82/laravel-envx - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. zeyad82/laravel-envx

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

zeyad82/laravel-envx
====================

Laravel custom env with validation

v1.2.1(7y ago)0358MITPHPPHP &gt;=5.6.4

Since Aug 7Pushed 7y ago1 watchersCompare

[ Source](https://github.com/zeyad82/laravel-envx)[ Packagist](https://packagist.org/packages/zeyad82/laravel-envx)[ RSS](/packages/zeyad82-laravel-envx/feed)WikiDiscussions master Synced yesterday

READMEChangelog (3)DependenciesVersions (7)Used By (0)

Laravel Envx
============

[](#laravel-envx)

Laravel Envx is a custom php environment file as an array so that it can have associative and multidimensional arrays with validation rules in order to avoid any unexpected behaviour especially if there are several instances of the project. This has been tested with laravel `5.6` and `5.7`.

Highlights
----------

[](#highlights)

- Make sure you don't go live without all required envx.php variables and without the correct values
- Validate envx.php variables using the Laravel Validator by defining rules in config/envx-validator.php
- Custom validation rule `required_ifany` to apply rules to an atrribute if another array attribute has a given value

Usage
-----

[](#usage)

Just like laravel env =&gt; `envx('attribute', 'default')`

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

[](#installation)

Via Composer:

```
    composer require zeyad82/laravel-envx
```

If you don't use auto-discovery, add the service provider your `config/app.php`:

```
    Zeyad82\LaravelEnvx\LaravelEnvxServiceProvider::class,
```

#### Publish configuration file

[](#publish-configuration-file)

```
    php artisan vendor:publish --tag="laravel-envx"
```

This will publish `config/envx-validator.php` and `envx.example.php` then run

```
    cp envx.example.php envx.php
```

If you will have different envx.php, add `envx.php` to `.gitignore` in your project root

If you will use envx in config files, the only way I found is to append the follwing to `bootstrap/app.php` after `ExceptionHandler`

```
$app->singleton('envx', function ($app) {
    return new Zeyad82\LaravelEnvx\EnvxService;
});
```

### Example configuration file

[](#example-configuration-file)

```
