如何在 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

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

How to use Redirect::intended in laravel?

phplaravellaravel-4

提问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 my routes image

我的路线 我的路线图片

If I put the the home resource route without the authfilter, 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 authfilter.I'm using laravel 4. Please help me...

但我想使用authfilter.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'));
});

I preffer named routes.

我喜欢命名路由。