【问题标题】:Laravel old() function not working --- flash dose not work (stoped working!!)Laravel old() 函数不工作 --- flash 不工作(停止工作!!)
【发布时间】:2018-04-16 20:14:35
【问题描述】:

我正在尝试在 Laravel 中使用 old(),但它不起作用。

在我的控制器中:

dd(back()->withInput());

这是会话结果

#session: Store {#364 ▼
#id: "dyNmtFJVQCQmcCob4SPYEBzWHJ6TJeM9X0mzWWu7"
#name: "laravel_session"
#attributes: array:6 [▼
  "_token" => "NVJATvxuHRlGbAC1jUEIjS6gbLQQEWPIIV41fLYd"
  "url" => []
  "_previous" => array:1 [▼
    "url" => "http://localhost:8000/units/23/rents/create"
  ]
  "_flash" => array:2 [▼
    "old" => []
    "new" => array:1 [▼
      0 => "_old_input"
    ]
  ]
  "login_web_59ba36addc2b2f9401580f014c7f58ea4e30989d" => 1
  "_old_input" => array:5 [▼
    "_token" => "NVJATvxuHRlGbAC1jUEIjS6gbLQQEWPIIV41fLYd"
    "contract_id" => "20"
    "unit_id" => "23"
    "amount_paid" => "1"
    "submit" => "submit"
  ]
]
#handler: FileSessionHandler {#363 ▶}
#started: true

value="{{ old('amount_paid')}}"我会得到空白字段

value="{{ old('amount_paid','test') }}"我会在现场得到“测试”

我正在使用 Laravel 5.6

编辑
澄清上面的代码它要调试
这是我的原始代码
控制器

return back()->withInput();

查看

<div class="form-group">
    <label> amount paid  </label>
    <input type="float" class="form-control" name="amount_paid" value="{{ old('amount_paid')}}" required>
</div>

添加处理请求的方法

        public function store(Request $request)
{
    // updating the amount paid
    $rent = new Rent;
    $rent->amount_paid = $request->amount_paid;


    try {
        $rent->save();
    } catch (\Illuminate\Database\QueryException $e) {
        //return to the form and populate it
        return back()->withInput();
    }
    return redirect('units/'.$request->unit_id);

** 更新 ** 看来 session->flash 不工作了。

我尝试了一个新的 laravel 安装,它工作正常

【问题讨论】:

  • 你在哪里使用它?你的看法?
  • 我以为你应该return back-&gt;with...() 而不是back()-&gt;with...() 或dd(back()-&gt;with...()) ??
  • 是的,我正在使用它
  • 你能添加处理请求的整个方法吗?
  • 我已经添加了。显然 flash 无法正常工作(仅适用于我的主应用程序)。我已经使用了新的灌输方法,它正在工作!

标签: laravel laravel-5.6


【解决方案1】:

问题与会话本身有关。

我有 2 个

\Illuminate\Session\Middleware\StartSession::class,  

一个在中间件中,另一个在 $middlewareGroups[web] 中。

这是几个月前在 youtube 上遵循教程实施本地化的结果:(

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-27
    • 1970-01-01
    • 1970-01-01
    • 2020-07-31
    • 1970-01-01
    • 2013-02-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多