美文网首页
laravel request 验证

laravel request 验证

作者: IthinkIcanfly | 来源:发表于2019-01-30 13:06 被阅读0次
$this->validate($request, [
   'title' => 'bail|required|string|between:2,32',
   'url' => 'sometimes|url|max:200',
   'picture' => 'nullable|string'
], [
   'title.required' => '标题字段不能为空',
   'title.string' => '标题字段仅支持字符串',
   'title.between' => '标题长度必须介于2-32之间',
   'url.url' => 'URL格式不正确,请输入有效的URL',
   'url.max' => 'URL长度不能超过200',
]);

门面模式

Validator::make($request->all(), [
   'title' => 'bail|required|string|between:2,32',
   'url' => 'sometimes|url|max:200',
   'picture' => 'nullable|string'
], [
   'title.required' => '标题字段不能为空',
   'title.string' => '标题字段仅支持字符串',
   'title.between' => '标题长度必须介于2-32之间',
   'url.url' => 'URL格式不正确,请输入有效的URL',
   'url.max' => 'URL长度不能超过200',
])->validate();

相关文章

网友评论

      本文标题:laravel request 验证

      本文链接:https://www.haomeiwen.com/subject/fmaqsqtx.html