PHP code example of ashallendesign / laravel-config-validator

1. Go to this page and download the library: Download ashallendesign/laravel-config-validator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ashallendesign / laravel-config-validator example snippets




use AshAllenDesign\ConfigValidator\Services\Rule;

return [
    Rule::make('driver')->rules(['in:smtp,sendmail,mailgun,ses,postmark,log,array']),
    // ...
];



use AshAllenDesign\ConfigValidator\Services\Rule;

return [
    Rule::make('driver')
        ->rules(['in:smtp,sendmail,mailgun,ses,postmark,log,array'])
        ->messages(['in' => 'The mail driver is invalid']),
    // ...
];



use AshAllenDesign\ConfigValidator\Services\Rule;

return [
    Rule::make('driver')
        ->rules(['in:smtp,sendmail,mailgun,ses,postmark,log,array'])
        ->environments([Rule::ENV_LOCAL]),
    
    Rule::make('driver')
        ->rules(['in:mailgun'])
        ->environments([Rule::ENV_PRODUCTION])
];


    
namespace App\Http\Controllers;

use AshAllenDesign\ConfigValidator\Services\ConfigValidator;

class TestController extends Controller
{
    public function index()
    {
        $configValidator = new ConfigValidator();

        $configValidator->run();

        return response()->json(['success' => true]);
    }
}

$configValidator = new ConfigValidator();

$configValidator->run(['auth']);

$configValidator = new ConfigValidator();

$configValidator->run([], 'app/Custom/Validation');

use AshAllenDesign\ConfigValidator\Services\ConfigValidator;
use AshAllenDesign\ConfigValidator\Services\Rule;

$configValidator = new ConfigValidator();

$configValidator->runInline([
    'app' => [
        Rule::make('env')->rules(['in:local,production']),
        Rule::make('debug')->rules(['boolean']),
    ],
    'mail' => [
        Rule::make('driver')->rules(['in:smtp,sendmail,mailgun,ses,postmark,log,array']),
    ],
]);



namespace App\Providers;

use AshAllenDesign\ConfigValidator\Services\ConfigValidator;
use Illuminate\Support\Facades\App;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    public function boot(ConfigValidator $configValidator)
    {
        if (App::environment() === 'local') {
            $configValidator->run();
        }
    }
}


$configValidator = new ConfigValidator();

$configValidator->throwExceptionOnFailure(false)
                ->run();

$errors = $configValidator->errors();


    
namespace App\Http\Controllers;

use ConfigValidator;

class TestController extends Controller
{
    public function index()
    {
        ConfigValidator::run();

        return response()->json(['success' => true]);
    }
}
bash
php artisan vendor:publish --tag=config-validator-defaults
 config/app.php 
bash
php artisan make:config-validation app
 config-validation/app.php 
 config/app.php 
 config-validation/app.php 
 app/mail.php 
 config-validation/mail.php 
 app/mail.php 
 ->run() 
 ->run() 
 auth.php 
 ->run() 
bash
php artisan config:validate
 auth.php 
bash
php artisan config:validate --files=auth
 auth.php 
 app.php 
bash
php artisan config:validate --path=app/Custom/Validation