方法Illuminate\Http\Request::first不存在于laravel 6错误中



我正在尝试将多列实现为唯一的(title,created_by(。用户不能创建重复的标题。验证在单独的请求类中也给了我错误。验证代码为:

$created_by = auth()->user()->id;
$this->validate($request, [
'title' => 'required|max:50|unique:register_types,title,null,id,created_by,'.$created_by
]);

代码给出错误为"Method Illuminate\Http\Request::first不存在">

但Validator方法成功工作。代码为:

$validator = Validator::make($request->all(),[
'title' => 'required|max:50|unique:register_types,title,null,id,created_by,'.$created_by
]);
if ($validator->fails()) {
return $validator->errors();
}

我想使用第一个干净的代码模式。这怎么可能?

我遇到了问题。几天前,我在处理程序类的render方法中添加了一个条件:

elseif ($exception instanceof ValidationException) {
return $exception->first();
}

解决方案:此时,只有我阻止了这种情况。问题解决了。

最新更新