Arafat Rahman
Arafat Rahman

Reputation: 1015

Session value isn't show in Laravel blade

I want to show username into top right side of my header in my laravel webpage but the value isn't shown.

After login successfully I have set the username into Session but the value doesn't show. No error shown also!

Controller

Session::put('user_id', $data->id);
Session::put('user_name', $data->name);
Session::put('user_email', $data->email);

return redirect('/home');

In blade

{{ Session::get('name') }}

How to solve that? Where is the problem? Anybody help please?

Upvotes: 2

Views: 1941

Answers (3)

Rwd
Rwd

Reputation: 35190

Going off the code in your question, you're looking for name but you haven't stored a value with name. I'm assuming it should be user_name. Try changing your code to be:

{{ Session::get('user_name') }}

Upvotes: 1

user9460442
user9460442

Reputation:

You should use the name user_name instead of name in your view

  {{ Session::get('user_name') }}

Upvotes: 1

Jithesh Jose
Jithesh Jose

Reputation: 1814

You should use the same name.. In controller you assigned value to another variable..

Session::put('user_id', $data->id);
Session::put('user_name', $data->name);
Session::put('user_email', $data->email);

So use that variables in your view.

 {{Session::get('user_id')}}
 {{Session::get('user_name')}}
 {{Session::get('user_email')}}

Upvotes: 2

Related Questions