请教:Auth::viaRemember () 这个东西是怎么用的..

Laravel 5.0.22
Auth::viaRemember()

根据手册 Auth::attempt 第二参已经传值为true

但是判断Auth::viaRemember()的时候怎样判断都是 False

为什么呢.是我用的方法不对吗?

《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
讨论数量: 8

为什么我加了Auth::check()还是return false啊?

Route::get('/', function(){
    //这里就 hardcode 了
    $credentials = [
        'name' => 'wjq',
        'password' => '123'
    ];

     if (Auth::attempt($credentials, true)) {
        return Redirect::intended('/dashboard');
    }
    return Redirect::to('login')->withMessage('Wrong credentials');
});

Route::get('dashboard', function(){
    return 'this is dashboard';
});

Route::get('checklogin', function(){
    if(Auth::check())
    {
    if (Auth::viaRemember()) {
        return 'yes';
    } else {
        return 'no';
    }
    }
});
7年前 评论

我也遇上这个问题,最后发现根本不需要用 Auth::viaRemember() 来做判断
只需要用Auth::check()就可以了。
如果沟选了【记住用户】,即使session过期了,Auth::check()也会从cookie中获取信息的,会自动登录。
只需要下面这么写就OK了。
if(Auth::check()){
return 'yes';
}else{
return 'no';
}

6年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!