How to fix Laravel Error Pages

MacTavish
2 min readMay 3, 2020

--

By default, Laravel error pages do not show the message passed as message parameter to abort functions. This is because the message is never accessed in error view files but a default text is provided which is always rendered.
A developer generated 500 error would like like this

Default view of 500 error

Don’t worry this does not need complex and long solution. It’s a two step solution.

  1. You have to publish the errors directory so you can edit the view files.
  2. Just paste small snippet in your error view file.

Enough talk, let’s roll.

Generate Errors directory

php artisan vendor:publish --tag=laravel-errors
  1. Pasting this command in terminal will publish the errors directory.

Modify View Code

2. Paste the above code in “500.blade.php”. To make it work for other pages as well, leave the “title section” as it is and replace the code and message section.

After modifying the “500.blade.php”, your view would represent the error message set by you in abort function. For example,

// Abort statement
abort(500, 'Could not upload image :(');
Modified View of 500 error displaying error message

An example to fix 503 error would look like

@extends('errors::minimal')

@section('title', __('Service Unavailable'))
// Let's paste the custom code and message section below
@section('code')
{{$exception->getStatusCode()}}
@endsection

@section('message')
{{$exception->getMessage()}}
@endsection

If this article helped you, be sure to give a response. I struggled with this thing until I figured it on my own.

--

--

MacTavish
MacTavish

Written by MacTavish

Contributor in Tor Project, Web developer, Gamer. I tend to write article to help beginners.

No responses yet