Package Data | |
---|---|
Maintainer Username: | bbrody |
Maintainer Contact: | sirajul.islam.anik@gmail.com (Syed Sirajul Islam Anik) |
Package Create Date: | 2023-05-03 |
Package Last Update: | 2023-05-03 |
Home Page: | https://packagist.org/packages/anik/form-request |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-17 03:10:42 |
Package Statistics | |
---|---|
Total Downloads: | 352 |
Monthly Downloads: | 7 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 0 |
Total Forks: | 0 |
Total Open Issues: | 0 |
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.
composer require anik/form-request
from your terminal being in the project
directory.\Anik\Form\FormRequestServiceProvider::class
to your bootstrap/app.php
as a provider.// bootstrap/app.php
$app->register(\Anik\Form\FormRequestServiceProvider::class);
Anik\Form\FormRequest
class.rules
method of the Anik\Form\FormRequest
class. Define your validation rules in it. Must return
an array.messages
method. Default is []
.attributes
method. Default is []
.authorize
method to define the authorization logic if the client is authorized to submit the form.
Must return a boolean value. Default is true
. When returning false
, it'll
raise \Illuminate\Auth\Access\AuthorizationException
exception.Illuminate\Validation\ValidationException
.
{"message": "The given data was invalid.", "errors": []}
format with status
code 422
. Handle the exception in app/Exceptions/Handler.php
's render
method if you want to modify the
response.statusCode
method to return the status of your choice. Must return int
. Default is 422
.errorMessage
method to return the message of your choice. Must return string
. Default
is The given data was invalid.
errorResponse
method to return response of your choice when the validation fails. Must return
either of type \Symfony\Component\HttpFoundation\Response
or null
.Laravel\Lumen\Http\Request
class is available in your request class.FormRequest::validated()
method will return the validated data when the validation passes.