Skip to content

Instantly share code, notes, and snippets.

@sword-jin
Created August 28, 2015 18:09
Show Gist options
  • Save sword-jin/a8f3642fb06fb3321b1e to your computer and use it in GitHub Desktop.
Save sword-jin/a8f3642fb06fb3321b1e to your computer and use it in GitHub Desktop.
处理 findOrFail 没有找到的 ModelNotFoundException
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if ($e instanceof ModelNotFoundException) {
return response()->json([
'error' => [
'message' => 'Resource Not Found.',
'status_code' => 404
]
], 404);
}
return parent::render($request, $e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment