Ramesh Murugesan
Ramesh Murugesan

Reputation: 5013

Laravel artisan route:list shows non-object Exception

I am new to laravel. Recently I cloned sample project from github. When I try to execute php artisan route:list shows

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');
        }

Upvotes: 2

Views: 557

Answers (1)

Maxim Lanin
Maxim Lanin

Reputation: 4531

When you fire artisan task, user object is not set, so \Auth::user() returns null and you see this error.

That's why you have to check if your app is running in console. You can do it via \App::runningInConsole() method.

Upvotes: 2

Related Questions