I think it's the most useless error message EVER.
"Whoops, looks like something went wrong."
Why can't it tell me what went wrong?
I already tried doing this but it still won't give me an error message.
I also tried adding this to the controller and view still nothing.
I also tried this in the app.php
'env' => env('APP_ENV', 'development'),
'debug' => env('APP_DEBUG', true),
I ended up doing die
every line just to know what went wrong.
I checked the storage and no error logs just .gitignore
And what went wrong? Well, I was using an object variable as an array.
So why didn't it tell me that? But instead made me play a game of where's Waldo?
It does display helpful error messages "not always just like now"
Can anyone help me how to always display a helpful error message on Laravel?
First of all, to show error messages in detail you need to have enabled the app-debug in your .env
file:
APP_LOG_LEVEL=debug
Now the interesting part.
Add this to your App\\Exceptions\\Handler.php
before the last }
:
/**
* Create a Symfony response for the given exception.
*
* @param \Exception $e
* @return mixed
*/
protected function convertExceptionToResponse(Exception $e)
{
if (config('app.debug')) {
$whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
return response()->make(
$whoops->handleException($e),
method_exists($e, 'getStatusCode') ? $e->getStatusCode() : 500,
method_exists($e, 'getHeaders') ? $e->getHeaders() : []
);
}
return parent::convertExceptionToResponse($e);
}
Source .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.