首页 > 解决方案 > 处理 Laravel Blade View::render() 异常

问题描述

我有一个辅助函数来渲染看起来像这样的动态视图

public function renderDynamicView($path, $data)
{
    return View::make($path, $data)->render();
}

现在,如果在提供的视图中发生异常(例如,在提供的视图中缺少信息$data),代码将只是废话。我如何在这个问题上放置一个通用的 try catch 来为这种情况呈现一个默认视图?我试过类似的东西

public function renderDynamicView($path, $data)
{
    try
    {
        return View::make($path, $data)->render();
    }
    catch (Exception $e)
    {
        return View::make('broken')->render();
    }
}

以上以某种方式导致Cannot end a section without first starting one.异常。

标签: phplaravellaravel-5laravel-blade

解决方案


推荐阅读