skip to Main Content

I want my admin user to impersonate my standard user. I’m using TenancyforLaravel package with single database multi-subdomain installation.

My admin user want to ghost login to my tenant dashboard console. I’m not able to achieve the impersonation. Can someone please guide me.

2

Answers


  1. You can do the following:
    Auth::login(User::find(1));
    or
    Auth::loginUsingId(1);
    in a route to authenticate as that user, check the laravel docs.

    Or you can use libraries like this
    laravel-impersonate
    to achieve what you expect with more to it (middleware, blades, configs etc). This is available till laravel 11.

    Login or Signup to reply.
  2. APP_KEY should be same in .env for all installations then do the following

    use IlluminateSupportFacadesAuth;
    
    Auth::login($user);
    

    or

    Auth::loginUsingId(1);
    

    explore the following links for detailed guide

    https://laravel.com/docs/11.x/authentication#authenticate-a-user-instance
    https://laravel.com/docs/11.x/authentication#authenticate-a-user-by-id

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search