[英]404 page laravel Middleware
我在laravel中有一個帶有管理員和用戶頁面的項目,但是我需要為管理員創建錯誤頁面,即
管理員\\
- 404-admin.blade.php
- 403-admin.blade.php
現場\\
- 404.blade.php
- 500.blade.php
如何指定每個部分對應的頁面? 謝謝
只需像下面的示例一樣更改您的Exception / Handler.php
public function render($request, Exception $exception)
{
$this->report($exception);
if ($exception instanceof ModelNotFoundException ||
$exception->getCode() == 403 ||
$exception instanceof MethodNotAllowedHttpException) {
if (!is_admin_site()) {
return view('user.403');
}
return view('admin.403');
}
if ($exception instanceof TokenMismatchException) {
return view('admin.501');
}
return parent::render($request, $exception);
}
所有錯誤頁面都重新路由至/resources/views/errors/(error code).blade.php
。 如果該頁面不存在,laravel將顯示服務器默認設置。 您可能尚未創建它們,因為它是可選的。 您可以將@ZeroOne的答案與這些錯誤頁面結合使用,可以根據需要隨意修改它們。
例如403.blade.php頁面。 如您所見,很容易將它們修改為您的請求:
@extends('layouts.app', [])
@section('content')
<div class="alert alert-warning alert-dismissible" role="alert">
<div class="row">
<div class="col-md-1">
<span class="material-icons align-bottom">error</span>
</div>
<div class="col-md-11">
<p class="bigger-150">503 Forbidden</p>
You don't have access to this page. Please <a href="{{ route('user.login') }}">login</a> or try something else. You may have lost your login
session. Consider checking the '<i>Remember me</i>' button at you login page next time. If you think this is an error or a bug, please <a
href="{{ route('home.contact') }}">contact us</a>. <br/><br/>
Thank you and sorry for the inconvenience.
</div>
</div>
</div>
@endsection
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.