Laravel 5.1使用变量重定向 [英] Laravel 5.1 Redirect with variable

查看:71
本文介绍了Laravel 5.1使用变量重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to redirect in Laravel like this:

在我的控制器中:

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

在我看来,我试图像这样获得它:

and in my view I try to get it like this:

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

但由于某种原因它不起作用,它一直为空.

but somehow it does not work, it keeps being empty.

我希望将其永久保存.

推荐答案

withErrors()与关联数组一起使用,就像这样:

Use withErrors() with an associative array instead, like so:

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

然后,您只需在视图中使用$ errors变量即可.

Then you can simply use the $errors variable in your view.

来自文档:

始终会定义$ errors变量,并且可以安全地使用它.这 $ errors变量将是Illuminate \ Support \ MessageBag的一个实例. 有关使用此对象的更多信息,请查看其对象. 文档.

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.

这篇关于Laravel 5.1使用变量重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆