mufasaparadox's avatar

How to use auth register in both guest and admin?

I'm using middleware and want to be able to register users as admin after logging in. Also, register should be enabled on guest too. Tried this change and it enables register after login as admin but not on guest and it's also available to all users and I want it enabled to admin only after authentication:

  public function __construct()
  {
      $this->middleware('auth');
      
  }

How to add guest as well? And determine if the user is an admin or not.

0 likes
4 replies
bobbybouwmann's avatar

Not really sure if I understand your question, but you want to determine if a guest or admin user can register a user? You can't determine of a guest user if they can register or not. It's always yes or no depending on what middleware the route or controller has.

If you want to open up a route for all users (guest or admin) you should just not give it the auth middleware. Then it's available for everyone ;)

However you can do that in your controller by excepting one of the methods from the middleware in your controller. For example

public function __construct()
{
    $this->middleware('auth')->except('register');
}
mufasaparadox's avatar

@bobbybouwmann Thank you for taking your time to answer me. But no. What I meant is that, if admin is logged in then admin should have the option to register a user and if no one is logged in, then register should be available too. The idea is to have a register option for admin and also for guests (no one is logged in). Is it more clear now? Let me know if you need more information. Please

bobbybouwmann's avatar
Level 88

I would probably make a different controller action for that. So you probably need some place to create users manually. The register method should be a seperate part in general from your admin panel. It's hard to reuse them like you wish

1 like

Please or to participate in this conversation.