【发布时间】:2017-09-02 10:57:49
【问题描述】:
我们在 Laravel 中使用表单请求验证。我正在尝试对 lumen 使用相同的请求,但它不能像预期的那样工作。
用户控制器
<?php
namespace App\Http\Controllers;
use App\Http\Requests\User\UserPostRequest;
use App\Macx\Logic\Interfaces\IUserLogic;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class UserController extends Controller
{
private $userLogic;
public function __construct(IUserLogic $userLogic)
{
$this->userLogic = $userLogic;
}
public function post(UserPostRequest $request)
{
return $this->userLogic->post(Auth::user(), $request->all());
}
}
UserPostRequest
<?php
namespace App\Http\Requests\User;
use Illuminate\Support\Facades\Request;
class UserPostRequest extends Request
{
/**
* 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 [
'name'=>'required|min:3|max:255',
'surname'=>'required|min:3|max:255',
'email'=>'required|email|unique:companies',
];
}
}
但是当我用一些帖子数据调用 /api/user/ 时,我收到了这个错误:
Call to undefined method App\Http\Requests\User\UserPostRequest::all()
注意:我刚刚看到 lumen 不支持文档中描述的表单请求验证:https://lumen.laravel.com/docs/5.4/validation
Lumen 不支持表单请求。如果你想使用表单请求,你应该使用完整的 Laravel 框架。
但是这个东西很有用,我还在努力寻找像表单请求验证这样的好解决方案。
【问题讨论】:
-
你跑
composer dump-autoload了吗? -
不,我可以在文档中找到相关信息。 Lumen 不支持表单请求验证。我正在尝试为此找到解决方案。 Lumen 不支持表单请求。如果你想使用表单请求,你应该使用完整的 Laravel 框架。