gpt4 book ai didi

php - Laravel 5.1 使用变量重定向

转载 作者:行者123 更新时间:2023-12-03 02:36:11 29 4
gpt4 key购买 nike

我正在尝试像这样在 Laravel 中重定向:

在我的 Controller 中:

  $state = false;
return redirect()->route('newPr')->with('errorMessageDuration', 'error', $state);

在我看来,我尝试这样做:

<input id="PrId" type="text" value="{{ isset($state) ? $state : '' }}">

但不知何故它不起作用,它一直是空的。

我希望它永久保存。

最佳答案

使用 withErrors() 与关联数组代替,如下所示:

return redirect()->route('newPr')->withErrors(compact('state'));

然后您可以简单地在 View 中使用 $errors 变量。

来自docs :

The $errors variable is always defined and can be safely used. The $errors variable will be an instance of Illuminate\Support\MessageBag. For more information on working with this object, check out its documentation.

关于php - Laravel 5.1 使用变量重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38260375/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com