如何使用 Laravel 框架的 validator
1个回答
展开全部
//验证规则 如果是修改可以重复 否则不能重复
if (isset($data['id'])){
$id = $data['id']?$data['id']:'null';
}else{
$id= 'null';
}
$rules = [
'title' => 'required|max:16|min:2|unique:helps,title,'.$id.',id,t_id,'.$tid,//过滤掉修改者本身,绑定选项tid
'type'=> 'required',
'sort' => 'integer',
'cat_id' => 'required',
'content'=>'required',
];
$validator = Validator::make($data,$rules);
if ($validator->fails()) {
return $this->error($validator->errors()->all()[0],null,true);
}
if (isset($data['id'])){
$id = $data['id']?$data['id']:'null';
}else{
$id= 'null';
}
$rules = [
'title' => 'required|max:16|min:2|unique:helps,title,'.$id.',id,t_id,'.$tid,//过滤掉修改者本身,绑定选项tid
'type'=> 'required',
'sort' => 'integer',
'cat_id' => 'required',
'content'=>'required',
];
$validator = Validator::make($data,$rules);
if ($validator->fails()) {
return $this->error($validator->errors()->all()[0],null,true);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询