基本上,您可以为每个HTTP错误代码定义一个页面并将其放入 resources/views/errors/
因此,如果要为404 HTTP响应创建视图,则应创建视图:
resources/views/errors/404.blade.php
Run Code Online (Sandbox Code Playgroud)
并且Laravel会自动将您的用户重定向到特定视图
此外,您可以自定义负责App\Exceptions\Handler从异常中呈现错误的类:render每次Exception上升时都会调用该 方法,因此您可以拦截HttpException由HTTP错误生成的内容并在任何位置重定向:
public function render($request, Exception $e)
{
//if $e is an HttpException
if ($e instanceof HttpException ) {
//get the status code
$status = $e->getStatusCode() ;
//if status code is 501 redirect to custom view
if( $status == 501 )
return response()->view('my.custom.view', [], 501);
}
return parent::render($request, $e);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4289 次 |
| 最近记录: |