目前,我的控制器会将CRUD操作委托给CRUDService。有没有办法检查验证器中是否存在更新/删除的资源? Laravel
例如,当我需要更新资源时,此请求首先通过验证程序,然后通过验证程序,然后通过CRUDService。如果这一发现资源不存在,它会与404
回应下面是执行此操作的代码片段:
public function update($id, Request $input)
{
if ($this->notFound($id)) {
return $this->response->notFound();
}
$input = $this->converter->convert($input);
$this->model->where("id", $id)->update($input);
return $this->response->updated();
}
private function notFound($id)
{
return !count($this->model->find($id));
}
我不知道是否有进行内部的这种检查方式FormRequest类...有什么建议吗?
更新后,这个返回更新的ID .. –
@D打码机对不起? – Caius