Laravel: Show authenticated username in redirect status message
P粉377412096
P粉377412096 2023-09-16 13:45:05
0
2
851

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?

P粉377412096
P粉377412096

reply all(2)
P粉821808309
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 );

    }
}
P粉154228483

Try this:

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);

        }
    }

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template