Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

202
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda