【发布时间】:2017-04-29 20:51:59
【问题描述】:
在我的项目中,我想使用验证器来检查是否已经存在。适用于单一存在。但是在模型添加中我想检查相同的模型不应该存在相同的类型和 make.with diff make or type 它会是好的,但不是相同的。
$input['name'] = Input::get('name');
$rules = array('name' => "unique:types,name");
$validator = Validator::make($input, $rules);
if ($validator->fails()) {
return Redirect::back()->with('alert-danger',"Type Name already exist.")->withInput();
} else {
$type = new Type();
$type_detail = $type->add_type($request);
$data['name'] = $request->name;
return redirect('/types')->with('alert-success', 'Type Created successfully.');
}
【问题讨论】:
-
你的问题不清楚。你能提供更多信息吗?
-
请说明您需要检查的内容。
-
好的。您可以使用 CustomValidation 规则来实现这一点。请检查这个 SO 问题:stackoverflow.com/questions/26121417/…
-
ex:在城市表中,我们添加添加州和国家。现在我想验证如果在城市表中输入城市时已经存在城市、州和国家,它应该已经显示城市错误exists.ex 我有城市记录,如城市-浦那、马哈拉施特拉邦、印度,然后我添加具有相同记录的同一个城市应该显示错误,但如果我添加浦那、古吉拉特邦、印度。我想要对此进行规则验证