anik/form-request
Form request is a package for Lumen that lets developer validate form requests like Laravel does.
397,886
50
| Install | |
|---|---|
composer require anik/form-request |
|
| Latest Version: | v5.0 |
| PHP: | ^7.2|^8.0 |
| Laravel: | 6 – 10 |
| Older releases: | 5 |
| License: | MIT |
| Last Updated: | Mar 2, 2024 |
| Links: | GitHub · Packagist |
Maintainer: ssi-anik
Form-Request

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.
Installation
- Install the package by running
composer require anik/form-requestfrom your terminal being in the project directory. - Register
\Anik\Form\FormRequestServiceProvider::classto yourbootstrap/app.phpas a provider.
// bootstrap/app.php
$app->register(\Anik\Form\FormRequestServiceProvider::class);
How to use?
- Create a class that extends
Anik\Form\FormRequestclass. - You must override
rulesmethod of theAnik\Form\FormRequestclass. Define your validation rules in it. Must return an array. - You can define validation messages by overriding
messagesmethod. Default is[]. - You can define custom pretty attribute names by overriding
attributesmethod. Default is[]. - You can override
authorizemethod to define the authorization logic if the client is authorized to submit the form. Must return a boolean value. Default istrue. When returningfalse, it'll raise\Illuminate\Auth\Access\AuthorizationExceptionexception. - If the validation fails, it will throw
Illuminate\Validation\ValidationException.- By default, it returns response in
{"message": "The given data was invalid.", "errors": []}format with status code422. Handle the exception inapp/Exceptions/Handler.php'srendermethod if you want to modify the response. - Override the
statusCodemethod to return the status of your choice. Must returnint. Default is422. - Override the
errorMessagemethod to return the message of your choice. Must returnstring. Default isThe given data was invalid. - Override the
errorResponsemethod to return response of your choice when the validation fails. Must return either of type\Symfony\Component\HttpFoundation\Responseornull.
- By default, it returns response in
- Now you can inject your Request class through the method injections. All the methods
of
Laravel\Lumen\Http\Requestclass is available in your request class. - The
FormRequest::validated()method will return the validated data when the validation passes.
Related Packages
andreaspabst/lumen-request-validation
Adds the Laravel ability to separate validations from the controller
267
1
shiftechafrica/lumen-take-off
Form request is a package for Lumen that lets developer validate form requests l...
118
0
albertcht/lumen-form-request
Form request is a package for Lumen that lets developer validate form requests l...
14,922
10
pearl/lumen-request-validate
Lumen doesn't have form request validator seperatly. This package helps develope...
411,564
45
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| v5.0 | ^7.2| | ^6.0| | MIT | |
| v4.5 | ^7.2| | ^6.0| | MIT | |
| v4.4 | ^7.2| | ^6.0| | MIT | |
| v4.3 | ^7.2| | ^6.0| | MIT | |
| v4.2 | ^7.2| | ^6.0| | MIT | |
| v4.1 | ^7.2| | ^6.0| | MIT | |
| v4.0 | ^7.3| | ^6.0| | MIT | |
| v3.3 | >=5.6 | ~5| | MIT | |
| v3.2 | >=5.6 | ~5| | MIT | |
| v3.1 | >=5.6 | ~5| | MIT | |
| v3.0 | >=5.6 | ~5| | MIT | |
| v2.0 | >=5.6 | ~5 | MIT | |
| v1.0 | >=5.6 | ~5 | MIT |