How do you create a custom 404 page in Laravel 5.6?

扶醉桌前 提交于 2020-01-21 19:53:50

问题


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.


回答1:


I found the answer by reading the Laravel Docs "Custom HTTP Error Pages".

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

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



来源:https://stackoverflow.com/questions/51256048/how-do-you-create-a-custom-404-page-in-laravel-5-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!