Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

201
Views
Show error page in Laravel?

Before I get into the question, I'll give you a brief introduction into what I want to do. I want to be able to show a friend;y view to users when a error happens in my Laravel project but unfortunately I don't know how to do this and was hoping some of you may be able to help me?

Hello. Today I am asking a question about Laravel. For a long time I have wanted to log EVERY single error in my laravel project. Now some of you may say that its easy, just overwrite the handle() method in the App\Exceptions\Handler class.

While that's relatively easy to do, it doesn't handle EVERY single error. I have noticed it doesn't handle Query exceptions.

What I am asking is how can I handle EVERY exception. What I mainly want to do is log the error in a database table, and disable a nice view to the end user. Then if I am the one, or another member of my team that receives the error, they can easily check in the database without having to show any critical details to the end user.

I followed this tutorial but it's the same, it doesn't log every single exception. http://blog.sarav.co/registering-custom-exception-handler-laravel-5/

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Use set_error_handler to set custom exception. Or you could use log4php they have a package for laravel I believe.

over 4 years ago · Santiago Trujillo Report

0

You can simply add some code in the App\Exceptions\Handler::render method, for example:

public function render($request, Exception $exception)
{
    if($exception instanceof \Illuminate\Database\QueryException) {
        // Do something with the $exception
        // dd($exception); // analyze it
        // return a response/redirect
    }

    return parent::render($request, $exception);
}

In this $exception instance, you can find many useful information using following methods (Omit magic methods, it's a dump of get_class_methods):

array:12 [▼
  0 => "__construct"
  1 => "getSql"
  2 => "getBindings"
  3 => "__wakeup"
  4 => "getMessage"
  5 => "getCode"
  6 => "getFile"
  7 => "getLine"
  8 => "getTrace"
  9 => "getPrevious"
  10 => "getTraceAsString"
  11 => "__toString"
]

Also, the property $exception->errorInfo will give you some information as well, for example (One particular errorInfo):

errorInfo: array:3 [▼
    0 => "42S22"
    1 => 1054
    2 => "Unknown column 'ids' in 'field list'"
]

Note: FYI, error and exception are two different things so the set_error_handler and the set_exception_handler both are for different reasons, an error handler will not catch an exception.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!