Laravel return 一个值,如果它不是唯一的
Laravel return a value if it is not unique
我正在使用 validation 检查该值在数据库中是否唯一,代码如下:
public function store(Request $request)
{
$select = 'select';
//logged in user id
$userid = Auth::user() -> id;
$usercountry = Auth::user() -> country;
$this -> validate($request, array(
'number' => 'required | unique:leads',
'website' => 'required | unique:leads',
'lead_source' => 'required | not_in:' . $select,
'industry' => 'required | not_in:' . $select,
'action' => 'required | not_in:' . $select
));
}
这很完美,但它显示了一条消息,告诉我 网站 输入是否重复。
我想要做的是 return 来自 table leads 的值,其中包含 website列。
I found this code:
if ($validator->fails()) {
$failedRules = $validator->failed();
}
我如何将其修改为 return 来自 潜在客户 table?
中相同重复行的值
也许,像这样的东西对你有用
$rules = [
'number' => 'required | unique:leads',
'website' => 'required | unique:leads',
'lead_source' => 'required | not_in:' . $select,
'industry' => 'required | not_in:' . $select,
'action' => 'required | not_in:' . $select
];
$data = [
'number.required' => 'number is required.',
'number.unique' => 'number has already been taken',
....
];
$validate = Validator::make($request->all(),$rules,$data);
if($validate->fails())
{
return redirect()->back()->withErrors($validate->errors())->withInput();
}
我正在使用 validation 检查该值在数据库中是否唯一,代码如下:
public function store(Request $request)
{
$select = 'select';
//logged in user id
$userid = Auth::user() -> id;
$usercountry = Auth::user() -> country;
$this -> validate($request, array(
'number' => 'required | unique:leads',
'website' => 'required | unique:leads',
'lead_source' => 'required | not_in:' . $select,
'industry' => 'required | not_in:' . $select,
'action' => 'required | not_in:' . $select
));
}
这很完美,但它显示了一条消息,告诉我 网站 输入是否重复。
我想要做的是 return 来自 table leads 的值,其中包含 website列。
I found this code:
if ($validator->fails()) {
$failedRules = $validator->failed();
}
我如何将其修改为 return 来自 潜在客户 table?
中相同重复行的值也许,像这样的东西对你有用
$rules = [
'number' => 'required | unique:leads',
'website' => 'required | unique:leads',
'lead_source' => 'required | not_in:' . $select,
'industry' => 'required | not_in:' . $select,
'action' => 'required | not_in:' . $select
];
$data = [
'number.required' => 'number is required.',
'number.unique' => 'number has already been taken',
....
];
$validate = Validator::make($request->all(),$rules,$data);
if($validate->fails())
{
return redirect()->back()->withErrors($validate->errors())->withInput();
}