试图获得非对象Laravel Auth的财产

时间:2015-09-10 07:26:25

标签: laravel authentication laravel-5 logout

编辑:我现在正在测试它,很奇怪,有时它会起作用,有时会给我这个错误。

我有一个应用程序,我已经覆盖了Laravel中的注销功能,所以我在AuthController.php

中有这个功能
public function getLogout()
{

    $userid = Auth::user()->id;

    date_default_timezone_set('Asia/Taipei');

    $today = date('Y-m-d');
    $logHour = new LoginHour();
    $checkLogin = $logHour->checkLoginHoursOut(intval($userid), $today);

    if($checkLogin != null)
    {
        $loginhours = '';
        $timestamp = date('Y-m-d h:i:s');
        $timestamp2 = strtotime($timestamp);

        $userLastLogin = $checkLogin[0]->timestamp;
        $userLastLogin2 = strtotime($userLastLogin);

        // Get difference in hours
        $diffHours = round(($timestamp2 - $userLastLogin2) / 3600, 2);


        LoginHour::where('date', '=', $today)->
                    where('user_id', '=', $userid)->
                    update(['loginhours' => $checkLogin[0]->loginhours + $diffHours, 'status' => 0, 'timestamp' => $timestamp]);
    }                    

    Auth::logout();

    return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/auth/login');
}

但出于某些原因,当我尝试注销时,我遇到了这个错误:

Trying to get property of non-object

这指向了这一行

$userid = Auth::user()->id;

可能是什么问题?我相信我仍然可以访问Auth因为我还没有在该行之前调用Auth::logout();吗?

0 个答案:

没有答案
相关问题