Search code examples
phplaravelauthenticationguard

Set, get Authentication Laravel 5?


I want to check user logging by Auth: My code (save email, password to Auth):

$userdata = array(
                'email'      => $email,
                'password'      => $password
            );
if(Auth::attempt($userdata))
{
      $this->auth->attempt($userdata);
      //$user = User::where('email',$email)->first();
      //Auth::login($user);           
      return redirect('admin');
}

When i ran this code, it take me to admin page. In admin page, i want to show auth (for test auth can be save or not), like this:

return var_dump(Auth->user());

for: __construct:

protected $auth;
public function __construct(Guard $auth)
{
    $this->auth = $auth;
}
public function handle($request, Closure $next)
{
    return var_dump($this->auth->user());        
}

I get NULL value. What is my problem? How can solve it?


Solution

  • You should use Auth::user() instead of Auth->user().