Laravel old()功能不起作用---闪光剂不起作用(停止工作!!)

时间:2018-04-16 20:14:35

标签: laravel laravel-5.6

我正在尝试在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-&gt; flash无效。

我尝试了一个新的laravel安装,它运行良好

1 个答案:

答案 0 :(得分:0)

问题与会话有关。

我有2个

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

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

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