skip to Main Content

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'")
:

enter image description here

What other method is there to get to the desired result?

2

Answers


  1. 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 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.

    Login or Signup to reply.
  2. 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 );
    
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search