I want to include the authenticated username when the user logs in and have the application redirect the user to the applicable page. In this specific example, the user will be redirected to their authenticated home page and the status message should read "Welcome back, {{Name}}"
The current message shows the code instead of 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 will return the following (the image contains the user
"role_as == '0'")
:
Are there any other ways to achieve the desired result?
Try this:
You should not use
{{}}
here as it only works on blade files.We also use
.
to concatenate strings and variables, such as'Hello' . $name代码>. Variables cannot be enclosed in quotes when you concatenate them.