I want to include the authenticated user’s name when the user log in and the application redirect the person to the applicable page. In this specific example the person is being redirected to their authenticated homepage and the status message should display "Welcome back, {{Name}}"
Currently the message displays the code and and not the actual value.
I have tried the following:
public function authenticated()
{
if(Auth::user()->role_as == '1') //Admin = 1
{
return redirect('admin/dashboard')->with('status', 'Welcome to your Admin Dashboard, {{ Auth::user()->name }}.');
}
else
{
return redirect('/home')->with('status', 'Welcome back,' . " " . '{{ Auth::user()->name }}');
}
}
This returns the following (image contains user with
"role_as == '0'")
:
What other method is there to get to the desired result?
2
Answers
Try this:
You shouldn’t use
{{}}
here bacause this only works for blade files.Also we use
.
to concat strings and variables like'Hello' . $name
. When you’re concating them the variable can’t be in quotations.