I want to call Auth::user() in the controller, but it doesn't work at first.
After passing in the Guard class, it can be called, as follows
public function display(Request $request,Guard $auth) {
$email=$auth->user()->getEmail ();
//Other statements
}
But I can get it directly using {{Auth::user()->getEmail}} in the blade template.
If you are using Laravel, you can theoretically use
Auth::user()
directly in the controller. To get a user’s email, you can do this directly:When using it like this, remember to declare it in the class header:
Or write directly like this: