我正在尝试在登录后设置一个简单的重定向。 日志记录部分有效,但重定向失败,因为它说路由不存在。
这是我的路线文件:
Route::any('/', array('uses' => 'UsersController@login'));
Route::any('/manage', array('uses' => 'AdminController@showWelcome'));
如果我去http://example.com/manage,路线就可以正常工作。 .. laravel 的 Logo 就在那里,我的其他页面也很好。
但是当我这样做时:
Redirect::route('/manage');
页面消失时显示:
Route [/manage] not defined
有人有想法吗?
最佳答案
当您使用Redirect::route
方法时,您应该使用路由名称,在这种情况下,您必须使用名称声明路由,即
Route::any('/manage', array('as' => 'manage', 'uses' => 'AdminController@showWelcome'));
这里,as
值是路由
的名称,所以,现在你可以使用
return Redirect::route('manage'); // 'manage' is the name of the route to redirect
或者,您也可以使用 Redirect::to('url')
方法,即
return Redirect::to('/manage'); // '/manage' is the url to redirect
关于php - Laravel 4 - 重定向时未定义路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18804356/