diff --git a/src/Flynsarmy/DbBladeCompiler/DbView.php b/src/Flynsarmy/DbBladeCompiler/DbView.php index 5ce4f01..5aa4fb0 100755 --- a/src/Flynsarmy/DbBladeCompiler/DbView.php +++ b/src/Flynsarmy/DbBladeCompiler/DbView.php @@ -1,12 +1,15 @@ renderContents(); + $usesState = version_compare(app()->version(), '5.4.0') >= 0; - $response = isset($callback) ? $callback($this, $contents) : null; + try { + $contents = $this->renderContents(); - // Once we have the contents of the view, we will flush the sections if we are - // done rendering all views so that there is nothing left hanging over when - // anothoer view is rendered in the future by the application developers. - // Before flushing, check Laravel version for correct method use - if (version_compare(app()->version(), '5.4.0') >= 0) - View::flushStateIfDoneRendering(); - else - View::flushSectionsIfDoneRendering(); + $response = isset($callback) ? $callback($this, $contents) : null; - return $response ?: $contents; + // Once we have the contents of the view, we will flush the sections if we are + // done rendering all views so that there is nothing left hanging over when + // anothoer view is rendered in the future by the application developers. + // Before flushing, check Laravel version for correct method use + if ($usesState) { + View::flushStateIfDoneRendering(); + } else { + View::flushSectionsIfDoneRendering(); + } + + return $response ?: $contents; + } catch (Throwable $exception) { + if ($usesState) { + View::flushState(); + } else { + View::flushSections(); + } + + throw $exception; + } } /**