Package Data | |
---|---|
Maintainer Username: | pearlkrishn |
Maintainer Contact: | pearlkrishn@gmail.com (pearlkrishn) |
Package Create Date: | 2018-02-14 |
Package Last Update: | 2023-04-17 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-23 03:11:29 |
Package Statistics | |
---|---|
Total Downloads: | 338,024 |
Monthly Downloads: | 3,676 |
Daily Downloads: | 22 |
Total Stars: | 45 |
Total Watchers: | 4 |
Total Forks: | 18 |
Total Open Issues: | 2 |
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.
composer require pearl/lumen-request-validate
$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.
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 [];
}
}
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
}
...