<?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']),
// ...
];
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]);
}
}