pearl / lumen-request-validate
Lumen doesn't have form request validator seperatly. This package helps developers to segregate the validation layer from the controller to a separate dedicated class
Installs: 334 325
Dependents: 3
Suggesters: 1
Security: 0
Stars: 45
Watchers: 4
Forks: 18
Open Issues: 2
Requires
- php: >=7.1.3
- illuminate/support: 5.7.* || 5.8.* || 6.* || 7.* || 8.* || 9.* || 10.*
- laravel/lumen-framework: 5.7.* || 5.8.* || 6.* || 7.* || 8.* || 9.* || 10.*
README
Lumen doesn't have form request validator seperatly. This package helps developers to segregate the validation layer from the controller to a separate dedicated class.
Installation
composer require pearl/lumen-request-validate
- Add the service provider in bootstrap/app.php
$app->register(Pearl\RequestValidate\RequestServiceProvider::class);
Next step is create your validator class using below console comment
php artisan make:request {class_name}
Request validator class will be create under app/Http/Requests folder.
Example:
Login validation class
<?php namespace App\Http\Requests; use Pearl\RequestValidate\RequestAbstract; class Login extends RequestAbstract { /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { return true; } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return [ "username" => "required", "password" => "required" ]; } /** * Get custom messages for validator errors. * * @return array */ public function messages() { return []; } }
How to use?
Now you can use your Request class in method injections
... use App\Http\Requests\Login; class ExampleController extends Controller { public function auth(Login $request) { //Login logic goes here } ...