Laravel工匠路线:列表显示非对象异常

时间:2015-09-02 09:29:47

标签: php laravel laravel-5

我是laravel的新手。最近我从github克隆了示例项目。当我尝试执行php artisan route:list节目

PHP Fatal error:  Call to a member function getMemberType() on a non-object in /...app/Http/Controllers/Admin/BaseAdminController.php on line 91

[Symfony\Component\Debug\Exception\FatalErrorException]    
Call to a member function getMemberType() on a non-object  

BaseAdminController.php

public function __construct(EmployeeDetails $employeeDetails)
    {
        $this->middleware('auth');

        if(Auth::user()->getMemberType() != 'employee') //Line 91
        {
            Auth::logout();
            return Redirect::to('secure/login');
        }

1 个答案:

答案 0 :(得分:2)

当您解雇工匠任务时,未设置用户对象,因此\Auth::user()会返回null,您会看到此错误。

这就是为什么你必须检查你的应用是否在控制台中运行的原因。您可以通过\App::runningInConsole()方法完成此操作。