如何在 Laravel 中使用 Redirect::intended?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21523223/
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
How to use Redirect::intended in laravel?
提问by manuthalasseril
I want the route to bypass authentication filter after successfully login. So I use Redirect::intended
. But it makes problem. Here is my code
我希望成功登录后绕过身份验证过滤器的路由。所以我使用Redirect::intended
. 但它会产生问题。这是我的代码
In LoginController@doLogin
在 LoginController@doLogin 中
if (Auth::attempt($credentials)) {
return Redirect::intended("home.index");
}
In Routes
在路线中
Route::group(array('before' => 'auth'), function() {
Route::resource('home', 'HomeController');
Route::get('/', 'HomeController');
});
My routes
我的路线
If I put the the home resource route without the auth
filter, then it will work. (Not redirect to login route.).That code is given below
如果我把没有auth
过滤器的 home 资源路由,那么它就会工作。(不重定向到登录路由。)下面给出了代码
Route::resource('home', 'HomeController');
Route::group(array('before' => 'auth'), function() {
Route::get('/', 'HomeController');
}); /* No Problem with this code */
But I want to work with auth
filter.I'm using laravel 4.
Please help me...
但我想使用auth
filter.I'm using laravel 4. 请帮帮我...
回答by JulianoMartins
Currently I use this:
目前我使用这个:
in filter.php
在过滤器.php
Route::filter('sentry', function() {
if (!Sentry::check())
{
return Redirect::route('authLogin');
}
});
so in route.php
所以在route.php
Route::get('auth/login/', array('as' => 'authLogin', 'uses' => 'AuthController@login'));
Route::post('auth/login/', array('as' => 'authLogin', 'uses' => 'AuthController@login'));
Route::group(array('before' => 'sentry'), function() {
Route::get('user/', array('as' => 'user', 'uses' => 'UserController@index'));
Route::get('user/index', array('as' => 'userIndex', 'uses' => 'UserController@index'));
});