Laravel:从控制器重定向到特定的 url

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46879464/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 16:51:23  来源:igfitidea点击:

Laravel: redirecting to a specific url, from controller

phplaravelcontrollerrouting

提问by Alfredo Soler

I'm having troubles to just redirect to a url from a controller.

我无法从控制器重定向到 url。

This is my trigger:

这是我的触发器:

<form method="POST" action="{{ url('creategroup") }}">

Then, this is the catcher:

然后,这是捕手:

Route::post('/creategroup', 'GroupController@store');

And finally, this is my method:

最后,这是我的方法:

public function store(Request $request) {
    /* bla bla bla */
    return Redirect::to('/users/'.$request->id.'/groups/');
}

But it doesn't work, the url just stops in localhost/creategroup and it shows a page that say that the page has expired, and it doesn't redirect to any place. Help please.

但它不起作用,该 url 只是在 localhost/creategroup 中停止,它显示一个页面,说该页面已过期,并且它不会重定向到任何地方。请帮忙。

回答by Lloople

Looks like a problem with csrfToken.

看起来像是 csrfToken 的问题。

Have you added the field on the form?

您是否在表单上添加了该字段?

{!! csrf_field() !!}

Learn more here

在此处了解更多信息

回答by utdev

This could happen due to the first backslash, try following:

这可能由于第一个反斜杠而发生,请尝试以下操作:

return redirect('users/'.$request->id.'/groups');