Download the PHP package anik/form-request without Composer
On this page you can find all versions of the php package anik/form-request. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download anik/form-request
More information about anik/form-request
Files in anik/form-request
Download anik/form-request
More information about anik/form-request
Files in anik/form-request
Vendor anik
Package form-request
Short Description Form request is a package for Lumen that lets developer validate form requests like Laravel does.
License MIT
Package form-request
Short Description Form request is a package for Lumen that lets developer validate form requests like Laravel does.
License MIT
Please rate this library. Is it a good library?
Informations about the package form-request
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-request
from your terminal being in the project directory. - Register
\Anik\Form\FormRequestServiceProvider::class
to yourbootstrap/app.php
as a provider.
How to use?
- Create a class that extends
Anik\Form\FormRequest
class. - You must override
rules
method of theAnik\Form\FormRequest
class. Define your validation rules in it. Must return an array. - You can define validation messages by overriding
messages
method. Default is[]
. - You can define custom pretty attribute names by overriding
attributes
method. Default is[]
. - You can override
authorize
method 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\AuthorizationException
exception. - 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
'srender
method if you want to modify the response. - Override the
statusCode
method to return the status of your choice. Must returnint
. Default is422
. - Override the
errorMessage
method to return the message of your choice. Must returnstring
. Default isThe given data was invalid.
- Override the
errorResponse
method to return response of your choice when the validation fails. Must return either of type\Symfony\Component\HttpFoundation\Response
ornull
.
- By default, it returns response in
- Now you can inject your Request class through the method injections. All the methods
of
Laravel\Lumen\Http\Request
class is available in your request class. - The
FormRequest::validated()
method will return the validated data when the validation passes.
All versions of form-request with dependencies
PHP Build Version
Package Version
The package anik/form-request contains the following files
Loading the files please wait ....