How to show user name session inside msg with toastr using Laravel PHP?

Asked

Viewed 297 times

1

Project is in PHP 7 with Laravel 5.8 using toastr for notifications, there is the possibility to put in the display of msg toastr info(example) the name of the user session?

using the session:

Auth::user()->name

My user controller:

      public function index()
{
    toastr()->success("Você está logado","{!! Auth::user()->name !!}");
    return view('home')->with('$user',Auth::user();
}
  • Wouldn’t it be simpler to concatenate the value? "Seja bem-vindo, " . Auth::user()->name

2 answers

1


Just concatenate the value in the method parameter success

toastr()->success("Você está logado " . Auth::user()->name);

0

Hello, taking into account that you are using the MVC standard, the simple way is to use the BLADE directives to display your data directly in the view.

view('home') -> with( '$user' , Auth::user()) ;

Here you already pass to the view the value indicated, in this case you treat this value in the view.

But this process can be accomplished in various ways, I believe that we must separate the back-end and front-end obligations as much as possible.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.