Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

204
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda