如果帐户未激活,则Laravel重定向

时间:2014-12-09 15:29:24

标签: php mysql laravel

我会粘贴代码以便您了解我想要做什么,基本上我做了一个路由过滤器并告诉我如果用户的帐户未激活我想重定向(我通过电子邮件发送)链路)。

Route::filter('activated', function()
{
    if (Session::get('account_activated') == 0)
    {
        return Redirect::to('myaccount', 'MyAccountController@notActive');
    }
});

Route::group(array('before' => 'auth'), function()
{
    // Only authenticated users may enter...
    Route::get('myaccount', 'MyAccountController@index');
});

当我登录时,我正在进入会话中" account_activated" key与数据库中的值(对应于用户)所以...... 当我试图进入这里时:

Route::group(array('before' => array('auth', 'activated')), function()
{
    // Only authenticated and activated users may enter...
    Route::get('sell', 'SellController@index');
});

我收到此错误:HTTP状态代码" 0"无效。 谁知道为什么会这样?谢谢!

2 个答案:

答案 0 :(得分:1)

如果要为路线使用多个过滤器,则必须将它们放在由|分隔的一个字符串中。

Route::group(array('before' => 'auth|activated'), function()
{
    // Only authenticated and activated users may enter...
    Route::get('sell', 'SellController@index');
});

<强>更新 状态代码0表示Laravel执行请求时出错。发生这种情况时,最好查看Laravel日志或Web服务器日志。

答案 1 :(得分:0)

过了一会儿,我结束了这样的事情:

Route::filter('active', function()
{
    //if account was not activated via e-mail, redirect to activate message view
    if (Session::get('account_activated') != 1){
        return Redirect::action('NotActiveAccountController@index');
    }
});

Route::group(array('before' => 'auth'), function()
{
    // Only authenticated users may enter...
    Route::get('myaccount', 'MyAccountController@index');
    Route::get('account_not_active', 'NotActiveAccountController@index');
});

Route::group(array('before' => 'auth|active'), function()
{
    // Only authenticated and active users may enter...
    Route::get('sell', 'SellController@index');
});

感谢jerodev的回答:D