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

后端 未结 1 612
感情败类
感情败类 2021-01-24 07:18

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 di

1条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-24 07:43

    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')
        

    {{ $exception->getMessage() }}

    back to home
    @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

    0 讨论(0)
提交回复
热议问题