Last active
May 18, 2019 13:48
-
-
Save ishikawam/98db18ef55b8d8146f6d4707ed8d026b to your computer and use it in GitHub Desktop.
Laravel5: エラーページを共通化〜どんなステータスコードでもどんと来い! ref: https://qiita.com/M_Ishikawa/items/1f0d72fc93286109464e
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
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<meta charset="UTF-8"> | |
</head> | |
<body> | |
@php | |
$status_code = $exception->getStatusCode(); | |
$message = $exception->getMessage(); | |
if (! $message) { | |
switch ($status_code) { | |
case 400: | |
$message = 'Bad Request'; | |
break; | |
case 401: | |
$message = '認証に失敗しました'; | |
break; | |
case 403: | |
$message = 'アクセス権がありません'; | |
break; | |
case 404: | |
$message = '存在しないページです'; | |
break; | |
case 408: | |
$message = 'タイムアウトです'; | |
break; | |
case 414: | |
$message = 'リクエストURIが長すぎます'; | |
break; | |
case 419: | |
$message = '不正なリクエストです'; | |
break; | |
case 500: | |
$message = 'Internal Server Error'; | |
break; | |
case 503: | |
$message = 'Service Unavailable'; | |
break; | |
default: | |
$message = 'エラー'; | |
break; | |
} | |
} | |
@endphp | |
<h1>{{ $status_code }} {{ $message }}</h1> | |
</body> | |
</html> |
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
resources/views/errors/404.blade.php |
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
resources/views/errors/404.blade.php | |
resources/views/errors/500.blade.php | |
resources/views/errors/503.blade.php | |
... |
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
{{ http_response_code() }} |
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
@php $guzzle = new GuzzleHttp\Psr7\Response; echo($guzzle->getStatusCode()); @endphp |
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
/** | |
* 共通エラーページ | |
*/ | |
protected function renderHttpException(\Symfony\Component\HttpKernel\Exception\HttpException $e) | |
{ | |
$status = $e->getStatusCode(); | |
return response()->view("errors.common", ['exception' => $e], $status); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment