glukkkk / lumen-request-validate
Lumen没有单独的表单请求验证器。此包帮助开发者将验证层从控制器分离出来,到一个独立的专用类中。
1.9
2024-08-30 13:50 UTC
Requires
- php: >=7.1.3
- illuminate/support: 5.7.* || 5.8.* || 6.* || 7.* || 8.* || 9.* || 10.* || 11.*
- laravel/lumen-framework: 5.7.* || 5.8.* || 6.* || 7.* || 8.* || 9.* || 10.* || 11.*
This package is auto-updated.
Last update: 2024-09-30 14:02:30 UTC
README
Lumen没有单独的表单请求验证器。此包帮助开发者将验证层从控制器分离出来,到一个独立的专用类中。
安装
composer require pearl/lumen-request-validate
- 在bootstrap/app.php中添加服务提供者
$app->register(Pearl\RequestValidate\RequestServiceProvider::class);
下一步是使用以下控制台注释创建你的验证器类
php artisan make:request {class_name}
请求验证器类将被创建在 app/Http/Requests 文件夹下。
示例
登录验证类
<?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 []; } }
如何使用?
现在你可以在方法注入中使用你的请求类
... use App\Http\Requests\Login; class ExampleController extends Controller { public function auth(Login $request) { //Login logic goes here } ...