在执行重定向之前,是否可以从另一个 class 中的重定向中检索值?

Is it possible to retrieve a value from a redirect in another class before performing the redirect?

我目前正在使用控制器,OnboardingController.php。这个控制器在不同的 class 中调用另一个方法,我们称它为 OnboardingService.php,例如:

入职控制器

public function doThing()
{
    return $this->doAnotherThing();
}

入职服务

public function doAnotherThing()
{
    return redirect('/')->with(['propertyA' => 'valueA']);
}

在返回重定向之前,我能否在 OnboardingController 中访问 propertyA?如果是这样,我将如何访问 属性?

例如

入职控制器

public function doThing()
{
    $doAnotherThing = $this->doAnotherThing();
    Log::info($doAnotherThing->propertyA);

    return $doAnotherThing;
}

我目前正在使用 Laravel 6。

您正在使用 redirect(...)->with(...) 刷新 propertyA,因此应该可以从会话访问 propertyA

public function doThing()
{
    $doAnotherThing = $this->doAnotherThing();
    Log::info(session()->get('propertyA'));

    return $doAnotherThing;
}