1. 程式人生 > >Laravel5.4中自定義404等錯誤頁面

Laravel5.4中自定義404等錯誤頁面

dtd app top exc auto get 1.0 存在 href

1.在resources/views/下簡歷文件夾error,在error文件中建立"404.blade.php文件"。

  

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"
/> 5 <title>404-對不起!您訪問的頁面不存在</title> 6 <style type="text/css"> 7 .head404{ width:580px; height:234px; margin:50px auto 0 auto; background:url(http://www.daixiaorui.com/Public/images/head404.png) no-repeat; } 8 .txtbg404{ width:499px; height:169px; margin:10px auto 0 auto; background:url(http://www.daixiaorui.com/Public/images/txtbg404.png) no-repeat
;} 9 .txtbg404 .txtbox{ width:390px; position:relative; top:30px; left:60px;color:#eee; font-size:13px;} 10 .txtbg404 .txtbox p {margin:5px 0; line-height:18px;} 11 .txtbg404 .txtbox .paddingbox { padding-top:15px;} 12 .txtbg404 .txtbox p a { color:#eee; text-decoration:none;} 13 .txtbg404 .txtbox p a:hover
{ color:#FC9D1D; text-decoration:underline;} 14 </style> 15 </head> 16 17 <body bgcolor="#494949"> 18 <div class="head404"></div> 19 <div class="txtbg404"> 20 <div class="txtbox"> 21 <p>對不起,您請求的頁面不存在、或已被刪除、或暫時不可用</p> 22 <p class="paddingbox">請點擊以下鏈接繼續瀏覽網頁</p> 23 <p><a style="cursor:pointer" onclick="history.back()">返回上一頁面</a></p> 24 <p><a href="">返回網站首頁</a></p> 25 </div> 26 </div> 27 </body> 28 </html>

2.修改app/Exceptions/Handler.php文件中的render函數,修改如下:

  

1 public function render($request, Exception $exception)
2   {
3     if ($exception) {
4       return response()->view(‘error.‘.$exception->getStatusCode(), [],$exception->getStatusCode());
5     }
6     return parent::render($request, $exception);
7   }

Laravel5.4中自定義404等錯誤頁面