laravel 8 api validation code example
Example 1: laravel validation example
use Illuminate\Support\Facades\Validator;
$validator = Validator::make(['data' => $value],
['data' => 'string|min:1|max:10']
);
if ($validator->fails()) {
}
$validator = Validator::make(['data' => $array],
['email' => 'string|min:1|max:10'],
['username' => 'string|min:1|max:10'],
['password' => 'string|min:1|max:10'],
['...' => '...']
);
if ($validator->fails()) {
}
Example 2: laravel 8 api validation
php artisan make:request StorePostRequest
Example 3: laravel validation
Validator::extendImplicit('foo', function ($attribute, $value, $parameters, $validator) {
return $value == 'foo';
});