版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。
protected function validateUser(Request $request) { $request->validate([ 'username' => 'required|min:2|max:10', 'mobile' => 'regex:/^1[345789][0-9]{9}$/|unique:users,mobile,' . $request->user()->id, 'sex' => 'required', ]); } $params = $request->all(); $params_id = $params['id'] ?? ''; $validator = Validator::make($request->all(), [ 'customer_name' => 'required|unique:customer,customer_name,'.$params_id, 'parent_id' => 'required', ], [ 'customer_name.required' => '客户名称不能为空!', 'customer_name.unique'=>'客户名称已经被占用', 'parent_id.required' => '顶级菜单不能为空', ]); if ($validator->fails()) { $rsp['err_msg'] = "数据校验失败"; $rsp['data'] = $validator->errors()->all(); return $this->getResponse('', ResponseCode::OK, $rsp); } 提供url: https://blog.csdn.net/lo6064200/article/details/104832750 解释说明 'name' => 'required|unique:test,display_name,11,age,extra_field,extraValue' 解释 对于客户端输入的 name 字段 name 不能为空 name 字段值在给定的数据库表中需为唯一值 // unique 校验规则 unique:table,colu