mardi 25 octobre 2016

Get authentication data inside of Constructor never in Laravel5.3.19

I have upgrade Laravel from 4.2 to laravel5.3 but I can't access Authentication data inside of Constructor of Controller

I have as below Middleware but it never work for me

use App\Http\Controllers\BaseController;

use Closure;
use Illuminate\Contracts\Auth\Guard;
use Redirect;
use Auth;
use App\User;


class DashboardController extends BaseController
{

    public $user;

    public function __construct(Guard $guard, User $user)
    {
        $this->middleware(function ($request, $next) {
            $this->user = Auth::user();
            return $next($request);
        });
        //$this->userID = Auth::user()?Auth::user()->id:null;

        dd($user);// Result attributes: []
        dd($guard);
        dd($this->user);

    }

}

The result after DD()

dd($guard); This is the result of $guard

DD($this->user);

NULL

It will return Null when I dd user property.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire