试图获得非对象laravel 5.3(Auth类)的属性

时间:2016-12-07 06:48:58

标签: php laravel authentication laravel-5 laravel-5.3

我使用laravel 5.3包。我在config/app.php上添加了我的包服务提供商,它运行正常。但是当我在包控制器上使用auth时显示错误
我登录并在其他控制器上正常工作。在laravel 5.2正常工作。但在5.3上显示错误

我的控制器:

     public function index()
     {

          return Auth::user()->name;
     }

错误:

Trying to get property of non-object
in TestController.php line 115
at HandleExceptions->handleError('8', 'Trying to get property of non-object', 'C:\wamp64php\www\test\modules\Test\Controller\TestController.php', '115', array()) in TestController.php line 115
at TestController->index()
at call_user_func_array(array(object(TestController), 'index'), array()) in Controller.php line 55
at Controller->callAction('index', array()) in ControllerDispatcher.php line 44
at ControllerDispatcher->dispatch(object(Route), object(TestController), 'index') in Route.php line 190
at Route->runController() in Route.php line 144
at Route->run(object(Request)) in Router.php line 642
at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Router.php line 644
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 618
at Router->dispatchToRoute(object(Request)) in Router.php line 596
at Router->dispatch(object(Request)) in Kernel.php line 268
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 150
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 117
at Kernel->handle(object(Request)) in index.php line 54

1 个答案:

答案 0 :(得分:2)

我解决了它 在kernel.php上添加这个middelware

\Illuminate\Session\Middleware\StartSession::class,