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?
You should use Auth::user()
instead of Auth->user()
.