[英]Laravel 5.1 how to redirect back to the current page after validation fails?
我有這條路:
Route::get('forgotten-password/confirm/{code}'
我想在驗證后無法返回到此確切路徑,但是它將我重定向到
Route::get('forgotten-password')
我使用Request類,因此它會自動進行驗證並返回我。 如果在控制器中是自定義的,則可以執行以下操作:
if ($validator->fails())
{
return redirect('forgotten-password/confirm/{code}');
}
有什么建議如何使其工作?
試試這個
public function store(Request $request)
{
$validator = Validator::make($request->all(), [
'title' => 'required|max:255',
'name' => 'required',
]);
if ($validator->fails()) {
return redirect('post/create')
->withErrors($validator)
->withInput();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.