如何在Laravel中进行简单的重定向? [英] How to do a simple redirect in Laravel?

查看:123
本文介绍了如何在Laravel中进行简单的重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Laravel中有一个功能.最后,我想重定向到另一个函数.我该如何在Laravel中做到这一点?

I have a function in Laravel. At the end I want to redirect to another function. How do I do that in Laravel?

我尝试过类似的事情:

return redirect()->route('listofclubs');

它不起作用. "listofclubs"的路线为:

It doesn't work. The route for "listofclubs" is:

Route::get("listofclubs","Clubs@listofclubs");

推荐答案

如果要使用路由路径,则需要使用to方法:

If you want to use the route path you need to use the to method:

return redirect()->to('listofclubs');

如果要使用route方法,则需要传递路由名称,这意味着您需要在路由定义中添加名称.因此,如果将您的路线修改为类似这样的名称:

If you want to use the route method you need to pass a route name, which means you need to add a name to the route definition. So if modify your route to have a name like so:

// The `as` attribute defines the route name
Route::get('listofclubs', ['as' => 'listofclubs', 'uses' => 'Clubs@listofclubs']);

然后您可以使用:

return redirect()->route('listofclubs');

您可以在 Laravel HTTP路由文档中了解有关命名路由的更多信息,并有关重定向的更多信息,请参见Redirector API文档.可用的方法以及它们各自接受的参数.

You can read more about named routes in the Laravel HTTP Routing Documentation and more about redirects in the Redirector class API Documentation where you can see the available methods and what parameters each of them accepts.

这篇关于如何在Laravel中进行简单的重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆