Improve view errors.
This commit is contained in:
parent
633c2bde83
commit
b043482905
|
|
@ -15,6 +15,18 @@ public static function exception($exception, $trace = true)
|
|||
|
||||
ob_get_level() and ob_end_clean();
|
||||
|
||||
$message = $exception->getMessage();
|
||||
|
||||
// For Laravel view errors we want to show a prettier error:
|
||||
$file = $exception->getFile();
|
||||
|
||||
if (str_contains($exception->getFile(), 'eval()') and str_contains($exception->getFile(), 'laravel/view.php'))
|
||||
{
|
||||
$message = 'Error rendering view: ['.View::$last['name'].']'.PHP_EOL.PHP_EOL.$message;
|
||||
|
||||
$file = View::$last['path'];
|
||||
}
|
||||
|
||||
// If detailed errors are enabled, we'll just format the exception into
|
||||
// a simple error message and display it on the screen. We don't use a
|
||||
// View in case the problem is in the View class.
|
||||
|
|
@ -22,9 +34,9 @@ public static function exception($exception, $trace = true)
|
|||
{
|
||||
echo "<html><h2>Unhandled Exception</h2>
|
||||
<h3>Message:</h3>
|
||||
<pre>".$exception->getMessage()."</pre>
|
||||
<pre>".$message."</pre>
|
||||
<h3>Location:</h3>
|
||||
<pre>".$exception->getFile()." on line ".$exception->getLine()."</pre>";
|
||||
<pre>".$file." on line ".$exception->getLine()."</pre>";
|
||||
|
||||
if ($trace)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -44,6 +44,13 @@ class View implements ArrayAccess {
|
|||
*/
|
||||
public static $cache = array();
|
||||
|
||||
/**
|
||||
* THe last view to be rendered.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $last;
|
||||
|
||||
/**
|
||||
* The Laravel view loader event name.
|
||||
*
|
||||
|
|
@ -387,6 +394,8 @@ public function get()
|
|||
*/
|
||||
protected function load()
|
||||
{
|
||||
static::$last = array('name' => $this->view, 'path' => $this->path);
|
||||
|
||||
if (isset(static::$cache[$this->path]))
|
||||
{
|
||||
return static::$cache[$this->path];
|
||||
|
|
|
|||
Loading…
Reference in New Issue