Created
August 28, 2015 18:09
-
-
Save sword-jin/a8f3642fb06fb3321b1e to your computer and use it in GitHub Desktop.
处理 findOrFail 没有找到的 ModelNotFoundException
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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