重定向回withInput()输出控件中的数据

时间:2019-06-04 00:57:01

标签: php laravel

我正在尝试使用输入重定向回去,但是没有将数据放回输入控件中。我是否在输入值中缺少输出指令?如果是这样,我认为要执行此操作的代码是什么?

$validator = Validator::make($request->all(), [
    'owner_firstname'       => 'required|min:2|max:30',
    'owner_lastname'        => 'required|min:2|max:30',
    'partner_firstname'     => 'required|min:2|max:30',
    'partner_lastname'      => 'min:2|max:30',
    'baby_firstname'        => 'min:2|max:30',
    'baby_lastname'         => 'min:2|max:30',
    'month'                 => 'not_in:0',
    'day'                   => 'not_in:0',
    'year'                  => 'numeric|digits:4',
    'guests_message'        => 'required|min:30|max:5000'
]);

if ($validator->fails()) {
    return redirect()->back()
        ->withErrors($validator)
        ->withInput();
}

<input type="text" id="owner_firstname" value="{{ what do I put here }}">

1 个答案:

答案 0 :(得分:1)

您必须使用old帮助程序来还原以前的值,并向输入中添加name属性。

<input type="text" id="owner_firstname" name="owner_firstname" value="{{ old('first_name') }}">

有关更多信息:https://laravel.com/docs/5.8/helpers#method-old