Skip to content

Form request is a package for Lumen that lets developer validate form requests like Laravel does.

License

Notifications You must be signed in to change notification settings

ssi-anik/form-request

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

  1. First of all, you will need composer installed. By running composer require anik/form-request from your terminal will install the package inside your project.
  2. Register Anik\Form\FormRequestServiceProvider to your bootstrap/app.php as a provider

How to use?

  1. Create a class that extends Anik\Form\FormRequest
  2. Override rule method from FormRequest class. Define your validation rules inside that method.
  3. You can define your messages by overriding messages method.
  4. authorize method is also available to guard the request. Return true or false from this method. This will raise Unauthorized exception.
  5. If the validation fails, it will throw exception of Anik\Form\ValidationException class. Handle it on your app/Exception/Handle.php file. getResponse method returns the messages.
  6. Now you can use your Request class in method injections. All the methods from Illuminate\Http\Request class is available.