Lumen Form request is a solution based on Form Request from laravel to provide modularized request validations.
Run command above do install with composer.
composer require brunocrpontes/lumen-form-request
- Add the following line to your
app.php
file:$app->register(LumenFormRequest\Providers\FormRequestServiceProvider::class);
- Create an
Request
class extending fromFormRequest.php
like above:<?php use LumenFormRequest\Requests\FormRequest; class ExampleFormRequest extends FormRequest { // DO YOUR VALIDATION HERE public function rules() : array { return [ 'email' => 'email|required' ]; } //IF YOU WISH RETURN WITH CUSTOM MESSAGES public function messages(): array { return [ 'email.required' => 'We need to know your e-mail address!', ]; } }