Laravel returns 在另一种方法中返回视图时出现空白页

Laravel returns blank page when view is returned in another method

伙计们,

我正在开发一个 Laravel 项目,出于项目结构的目的,我试图通过调用位于与 class 相同的方法来 return 视图触发它的功能。 (见代码)

现在这个案例完美了

public function pay()
{
    $navActive = true;
    return view('steps.pay', compact('navActive'));
}

但是当我这样做时它会return一个空白页

public function pay()
{
    $navActive = true;
    $this->test($navActive);
}

public function test($navActive)
{
    return view('steps.pay', compact('navActive'));
}

请记住视图的名称是正确的,视图存在,如果我在方法中使用 dd('with some message') 它应该 return 视图,它将被触发。

有什么想法吗?到目前为止,我花了很多时间试图找到答案,我不确定我错过了什么。

谢谢!

您的 test 方法只是 return 在 pay 方法的视图中 - 您还需要 return 从那个:

public function pay()
{
    $navActive = true;
    return $this->test($navActive);
}

你忘了"return"

public function pay()
{
    $navActive = true;
    return $this->test($navActive);
}

public function test($navActive)
{
    return view('steps.pay', compact('navActive'));
}