PHPackages                             ashallendesign/laravel-config-validator - 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. ashallendesign/laravel-config-validator

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

ashallendesign/laravel-config-validator
=======================================

A package for validating your Laravel app's config.

v2.10.0(2mo ago)217905.3k—3.3%11[1 issues](https://github.com/ash-jc-allen/laravel-config-validator/issues)3MITPHPPHP ^8.2

Since Oct 11Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/ash-jc-allen/laravel-config-validator)[ Packagist](https://packagist.org/packages/ashallendesign/laravel-config-validator)[ Docs](https://github.com/ash-jc-allen/laravel-config-validator)[ GitHub Sponsors](https://github.com/ash-jc-allen)[ RSS](/packages/ashallendesign-laravel-config-validator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (18)Versions (33)Used By (3)

[![](https://camo.githubusercontent.com/4e22c627a711be0ab520a670cb8f8d21fe1a212950d19d08f7690a633a7846a5/68747470733a2f2f617368616c6c656e64657369676e2e636f2e756b2f696d616765732f637573746f6d2f6c61726176656c2d636f6e6669672d76616c696461746f722d6c6f676f2e706e67)](https://camo.githubusercontent.com/4e22c627a711be0ab520a670cb8f8d21fe1a212950d19d08f7690a633a7846a5/68747470733a2f2f617368616c6c656e64657369676e2e636f2e756b2f696d616765732f637573746f6d2f6c61726176656c2d636f6e6669672d76616c696461746f722d6c6f676f2e706e67)

[![Latest Version on Packagist](https://camo.githubusercontent.com/657b5f235f6ef886f1c4febad8731eab9defd40bfec63fb09aa1620e7d37a89e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f617368616c6c656e64657369676e2f6c61726176656c2d636f6e6669672d76616c696461746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ashallendesign/laravel-config-validator)[![Build Status](https://camo.githubusercontent.com/ad383cd155a8aaf6eef43b1f08a74a8cea2750ddd8ce3b661264461ae9bfb7c7/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6173682d6a632d616c6c656e2f6c61726176656c2d636f6e6669672d76616c696461746f722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/ash-jc-allen/laravel-config-validator)[![Total Downloads](https://camo.githubusercontent.com/793918e6268fd2a873786d200570c60fe50ad4d8d264dd8134452198bb83a4a3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f617368616c6c656e64657369676e2f6c61726176656c2d636f6e6669672d76616c696461746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ashallendesign/laravel-config-validator)[![PHP from Packagist](https://camo.githubusercontent.com/c35de7885997304f7f3ec53c6c64988e8f6adb2ca4fe0be28bf2878c62f7693e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f617368616c6c656e64657369676e2f6c61726176656c2d636f6e6669672d76616c696461746f723f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ashallendesign/laravel-config-validator)[![GitHub license](https://camo.githubusercontent.com/157c868070a7bf9bb5e345f2c15b178621cfe706dc5788b724f2120069be4569/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6173682d6a632d616c6c656e2f6c61726176656c2d636f6e6669672d76616c696461746f723f7374796c653d666c61742d737175617265)](https://github.com/ash-jc-allen/laravel-config-validator/blob/master/LICENSE)

Table of Contents
-----------------

[](#table-of-contents)

- [Overview](#overview)
- [Installation](#installation)
    - [Requirements](#requirements)
    - [Install the Package](#install-the-package)
    - [Publishing the Default Rulesets](#publishing-the-default-rulesets)
- [Usage](#usage)
    - [Creating a Validation Ruleset](#creating-a-validation-ruleset)
        - [Using the Generator Command](#using-the-generator-command)
        - [Ruleset Location](#ruleset-location)
        - [Adding Rules to a RuleSet](#adding-rules-to-a-ruleset)
        - [Custom Validation Error Messages](#custom-validation-error-messages)
        - [Only Running in Specific App Environments](#only-running-in-specific-app-environments)
    - [Running the Validation](#running-the-validation)
        - [Running the Validation Manually](#running-the-validation-manually)
            - [Only Running on Selected Config Files](#only-running-on-selected-config-files)
            - [Custom Folder Path](#custom-folder-path)
        - [Using the Command](#using-the-command)
            - [Only Running on Selected Config Files (Command)](#only-running-on-selected-config-files-command)
            - [Custom Folder Path (Command)](#custom-folder-path-command)
        - [Using a Service Provider](#using-a-service-provider)
        - [Throwing and Preventing Exceptions](#throwing-and-preventing-exceptions)
    - [Facade](#facade)
- [Security](#security)
- [Contribution](#contribution)
- [Changelog](#changelog)
- [Upgrading](#upgrading)
- [License](#license)

Overview
--------

[](#overview)

A Laravel package that allows you to validate your config values and environment.

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

[](#installation)

### Requirements

[](#requirements)

The package has been developed and tested to work with the following minimum requirements:

- PHP 8.0
- Laravel 8

### Install the Package

[](#install-the-package)

You can install the package via Composer:

```
composer require ashallendesign/laravel-config-validator
```

### Publishing the Default Rulesets

[](#publishing-the-default-rulesets)

To get you started with validating your app's config, Laravel Config Validator comes with some default rulesets. To start using these rulesets, you can publish them using the following command:

```
php artisan vendor:publish --tag=config-validator-defaults
```

The above command will copy the validation files and place in a `config-validation` folder in your project's root. These rules are just to get you started, so there are likely going to be rule in the files that don't apply to your app. So, once you've published them, feel free to delete them or edit them as much as you'd like.

Usage
-----

[](#usage)

### Creating a Validation Ruleset

[](#creating-a-validation-ruleset)

#### Using the Generator Command

[](#using-the-generator-command)

This package comes with a command that you can use to quickly create a validation file to get you started right away. Lets say that you wanted to create a validation file for validating the config in the `config/app.php` file. To do this, you could use the following command:

```
php artisan make:config-validation app
```

Running the above command would create a file in `config-validation/app.php` ready for you to start adding your config validation.

#### Ruleset Location

[](#ruleset-location)

To validate your application's config, you need to define the validation rules first. You can do this by placing them inside files in a `config-validation` folder with names that match the config file you're validating. As an example, to validate the `config/app.php` config file, you would create a new file at `config-validation/app.php` that would hold the rules.

#### Adding Rules to a Ruleset

[](#adding-rules-to-a-ruleset)

Once you have your ruleset file created in the `config-validation` folder, you can start adding your validation rules.

Under the hood, Laravel Config Validator uses the built-in `Validator` class, so it should seem pretty familiar to work with. To check out the available Laravel validation rules that can be used, [click here](https://laravel.com/docs/8.x/validation#available-validation-rules).

As an example, we might want to add a config validation rule to ensure that the `driver` field in the `app/mail.php`file is a supported field. To do this, we could create a file at `config-validation/mail.php` with the following:

```
