简体   繁体   English

验证失败后,Laravel 5.1如何重定向回当前页面?

[英]Laravel 5.1 how to redirect back to the current page after validation fails?

I have this path: 我有这条路:

Route::get('forgotten-password/confirm/{code}'

And I want after validation failing to return to this exact path, but it redirects me one step more to 我想在验证后无法返回到此确切路径,但是它将我重定向到

Route::get('forgotten-password')

I use Request classes, so it automatically makes the validations and returns me back. 我使用Request类,因此它会自动进行验证并返回我。 If it was custom in the controller, I could make: 如果在控制器中是自定义的,则可以执行以下操作:

if ($validator->fails())
{
    return redirect('forgotten-password/confirm/{code}');
}

Any suggestions how to make it work? 有什么建议如何使其工作?

Try this way 试试这个

 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM