【发布时间】:2016-03-28 20:17:29
【问题描述】:
如何在 Laravel 中验证 Patch/Put 请求
根据 Laravel 文档 http://laravel.com/docs/5.1/controllers,put/patch 请求由资源控制器的 update 操作处理
Verb Path Action Route Name
PUT/PATCH /photo/{photo} update photo.update
由于patch 请求应该更新部分资源而put 请求更新整个资源,那么我的FormRequest 验证rules 应该如何:
我应该这样做吗:
public function rules()
{
$rules = [];
if($this->has('name')) $rules['name'] = 'required';
if($this->has('email')) $rules['email'] = 'required|email';
return $rules;
}
依靠您的专业答案。
【问题讨论】:
-
为什么不使用验证器中的
sometimes方法。是specifically made for these sort of things。 -
谢谢@Andrew 我知道
sometimes但你不能在FormRequest中使用sometimes我更喜欢使用 -
@Digitlimit 只需在
FormRequest类中覆盖默认的getValidatorInstance即可