ssi-anik / form-request by ssi-anik

Form request is a package for Lumen that lets developer validate form requests like Laravel does.
277,745
49
3
Package Data
Maintainer Username: ssi-anik
Maintainer Contact: sirajul.islam.anik@gmail.com (Syed Sirajul Islam Anik)
Package Create Date: 2017-08-25
Package Last Update: 2024-03-02
Home Page: https://packagist.org/packages/anik/form-request
Language: PHP
License: MIT
Last Refreshed: 2024-12-15 15:07:42
Package Statistics
Total Downloads: 277,745
Monthly Downloads: 7,340
Daily Downloads: 87
Total Stars: 49
Total Watchers: 3
Total Forks: 25
Total Open Issues: 1

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.