带输入的重定向路由
Redirect route with input
考虑这种情况,我有以下一对路线:
Route::post('cart/update', ['uses' => 'CartController@update', 'as' => 'cart.update']);
Route::match(['get', 'post'], 'order/checkout', ['uses' => 'OrderController@checkout', 'as' => 'order.checkout']);
在 cart.update
路线中,如果我这样做:
return Redirect::route('order.checkout')->withInput();
然后我在 order.checkout
使用 dd(Input::all())
,我收到一个空数组。
但是,如果我要使用 dd(Input::old())
,那么我会收到包含我期望的输入值的数组。
它应该表现得像那样吗?
我不应该在 order.checkout
路线正确接收 Input::all()
吗?
来自 Laravel 文档:http://laravel.com/docs/4.2/requests#old-input
You may need to keep input from one request until the next request.
For example, you may need to re-populate a form after checking it for
validation errors.
Since you often will want to flash input in association with a
redirect to the previous page, you may easily chain input flashing
onto a redirect.
所以是的,行为是正确的。例如,您应该使用 Input::old() 来潜在地重新填充可能未通过验证的表单。
考虑这种情况,我有以下一对路线:
Route::post('cart/update', ['uses' => 'CartController@update', 'as' => 'cart.update']);
Route::match(['get', 'post'], 'order/checkout', ['uses' => 'OrderController@checkout', 'as' => 'order.checkout']);
在 cart.update
路线中,如果我这样做:
return Redirect::route('order.checkout')->withInput();
然后我在 order.checkout
使用 dd(Input::all())
,我收到一个空数组。
但是,如果我要使用 dd(Input::old())
,那么我会收到包含我期望的输入值的数组。
它应该表现得像那样吗?
我不应该在 order.checkout
路线正确接收 Input::all()
吗?
来自 Laravel 文档:http://laravel.com/docs/4.2/requests#old-input
You may need to keep input from one request until the next request. For example, you may need to re-populate a form after checking it for validation errors.
Since you often will want to flash input in association with a redirect to the previous page, you may easily chain input flashing onto a redirect.
所以是的,行为是正确的。例如,您应该使用 Input::old() 来潜在地重新填充可能未通过验证的表单。