如何在Laravel 5.6中创建自定义404页面? [英] How do you create a custom 404 page in Laravel 5.6?
问题描述
我还没有找到任何有关如何在Laravel 5.6的特定版本中正确"创建404页面的教程.我发现有些过时的东西与Laravel 5.6的工作方式有些不同.任何输入都会有所帮助.
I have not found any tutorials out there that address how to "properly" create a 404 page in this specific version of Laravel 5.6. I found some outdated once that is a bit different that how Laravel 5.6 works. Any inputs will help.
推荐答案
我通过阅读Laravel文档自定义HTTP错误页面"找到了答案.
I found the answer by reading the Laravel Docs "Custom HTTP Error Pages".
在"/resources/views/"下创建一个错误"文件夹,并创建一个名为"404.blade.php"的文件,然后添加以下代码:
Create a "Errors" Folder under "/resources/views/" and create a file named "404.blade.php" then add this code:
@extends('../layouts.app')
@section('content')
<div id="login-container" class="container-fluid" style="background-color: lightgray;">
<div class="row">
<div class="col-md-12 mt-1 mb-1 text-center">
<h1>{{ $exception->getMessage() }}</h1>
<a href="{{ asset('/') }}">back to home</a>
</div>
</div>
</div>
@endsection
然后将此路由添加到您的"web.php"文件中:
then add this route to your "web.php" file:
// 404 Route Handler
Route::any('{url_param}', function() {
abort(404, '404 Error. Page not found!');
})->where('url_param', '.*');
我已经写了一个博客:单击此处
I have written a blog about it: click here
这篇关于如何在Laravel 5.6中创建自定义404页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!