我希望在包含POST表单的3个页面中保留相同的网址。
当表单验证失败时,我正在进行\Redirect::back()->withErrors()
,但如果我在第二页上,它将返回第1页。如何返回第2页而不是第1页?
我的路线是:
Route::post("/test",['as'=>'test','uses'=>'TestController@post']);
Route::get("/test",function(){ return View::make("pages.test"); });
我的控制器是:
class TestController extends Controller
{
function post(Request $request){
if($request->has("test1")){
return view('/pages/test2');
}elseif($request->has("test2")){
return \Redirect::back()->withErrors(["my error"]);
}else{
return "unknown test";
}
}
}
我的刀片文件是test.blade.php:
{{ Form::open(['action' => ['TestController@post']]) }}
Test1
{{ Form::hidden('test1', "test1")}}
{{ Form::submit('CONTINUE')}}
{{ Form::close() }}
test2.blade.php:
{{ Form::open(['action' => ['TestController@post']]) }}
test2
{{ Form::hidden('test2', "test2") }}
{{ Form::submit('CONTINUE')}}
{{ Form::close() }}
当return \Redirect::back()->withErrors(["my error"]);
执行时,我希望返回test2.blade.php,但我将返回test.blade.php。我该如何解决这个问题?
答案 0 :(得分:2)
您不应在return view()
请求中使用post
。
这是商店的请求周期示例:
GET - show view 1 (shopping-cart)
POST - it's a form submmited from view 1
- if it fails, it redirect to view 1
- after doing the app logic, it redirects to view 2
GET - show view 2 (payment-method)
POST - it's a form submmited from view 2
- if it fails, redirect back will go to view 2
- if it succeded, should redirect to view 3
GET - show view 3 (order confirmation)
此问题将随此路径结构消失