search

Home  >  Q&A  >  body text

laravel - Why can Auth::user, DB::() and other statements be directly called in the blade template?

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.

淡淡烟草味淡淡烟草味2841 days ago760

reply all(1)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-16 16:57:35

    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:

    Auth::user()->email

    When using it like this, remember to declare it in the class header:

    use Auth;

    Or write directly like this:

    \Auth::user()->email

    reply
    0
  • Cancelreply