\ _Noh :: user()在5.3.6中为空?

时间:2016-09-07 07:58:14

标签: laravel laravel-5.2 laravel-5.1 laravel-5.3

这是关于Laravel 5.3.6

我能够成功登录,登录后可以查看Auth User。我可以显示Auth::guard()当前用户对象的确切位置。以下是详细信息。

  
      
  1. 转到登录控制器
  2.   
  3. 转到AuthenticatesUsers Trait
  4.   
  5. 转到sendLoginResponse方法。用户成功到达此处,因为用户已成功通过身份验证。
  6.   

这里我可以检查$this->guard()->user()是否有当前用户值。但是当控制到达角色控制器时......我试图像dd(Auth::guard());那样访问它,并且值为null。我还在角色控制器中添加了以下参考。

use Illuminate\Support\Facades\Auth;

以下是我的角色控制器路线。

Route::group(['middleware' => ['auth']], function () {
    Route::get('/Roles',              
        array (
            'uses'  => 'Website\Role\RoleController@index',      
            'as'    => 'Roles'
        )
    );
});

你在Laravel 5.3.6中遇到过这种问题吗?

\Auth::guard()的输出低于。

SessionGuard {#162 ▼
  #name: "web"
  #lastAttempted: null
  #viaRemember: false
  #session: Store {#165 ▶}
  #cookie: CookieJar {#167 ▶}
  #request: Request {#40 ▶}
  #events: Dispatcher {#5 ▶}
  #loggedOut: false
  #tokenRetrievalAttempted: false
  #user: null
  #provider: EloquentUserProvider {#158 ▶}
}

1 个答案:

答案 0 :(得分:0)

Kernel.php文件如下所示

//--------------- carInfo.jsx ---------------
import React from 'react';

const renderWhenData = ( info ) => {
  console.log( 'info is ' +info); //<<<<<<<<<<<<<<<<<<< undefined
  if ( info ) {
    return <span>{ info.description }</span>;
};

export let Info = ( { info } ) => (
  <p>{ renderWhenData( info ) }</p>
);

//--------------- carClass.jsx ---------------
import React from 'react';
import ReactDOM from 'react-dom';
import { composeWithTracker } from 'react-komposer';
import { Info } from '../ui/carInfo.jsx';

const composer = (props, onData) => {
  const subscription = Meteor.subscribe('vehicles');
  if (subscription.ready()) {
    const cars = Vehicles.findOne({name: 'Jack'});  //<<<<<<<<<<<<<<< document OK.
    onData(null, { cars });
  }
};

const Container = composeWithTracker(composer)(Info);
ReactDOM.render(<Container />, document.getElementById('react-info'));

我将其更改为以下内容。

protected $middleware = [
    \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
];

protected $middlewareGroups = [
    'web' => [
        \App\Http\Middleware\EncryptCookies::class,
        \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
        \Illuminate\Session\Middleware\StartSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
        \App\Http\Middleware\VerifyCsrfToken::class,
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
    ],

    'api' => [
        'throttle:60,1',
        'bindings',
    ],
];