Form request is a package for Lumen that lets developer validate form requests like Laravel does.
A package that helps developer to segregate the validation logic from controller to a separate dedicated class. Lumen doesn't have any
FormRequest class like Laravel. This will let you do that.
- First of all, you will need composer installed. By running
composer require anik/form-requestfrom your terminal will install the package inside your project.
bootstrap/app.phpas a provider
- Create a class that extends
FormRequestclass. Define your validation rules inside that method.
- You can define your messages by overriding
authorizemethod is also available to guard the request. Return
falsefrom this method. This will raise
- If the validation fails, it will throw exception of
Anik\Form\ValidationExceptionclass. Handle it on your
getResponsemethod returns the messages.
- Now you can use your Request class in method injections. All the methods from
Illuminate\Http\Requestclass is available.