4 months ago

Redirect to subdomain after register

Posted 4 months ago by imposition

Hi there, I'm messing around with Multi tenancy but now i don't know how to make my default register form redirect my user to it's subdomain.

Here is my register method:

    protected function create(array $data)
        $user = User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
        Artisan::call('tenant:create', ['name' => $data['name'], 'email' => $data['email'], 'password' => $data['password']]);
        return $user;

It's calling this command:

 public function handle()
        $name = $this->argument('name');
        $email = $this->argument('email');
        $password = $this->argument('password');

        if (Tenant::tenantExists($name, $email)) {
            $this->error("A tenant with name '{$name}' already exists.");

        $tenant = Tenant::registerTenant($name, $email, $password);
        $this->info("Tenant '{$name}' is created and is now accessible at {$tenant->hostname->fqdn}");

        // invite admin
        $tenant->admin->notify(new TenantCreated($tenant->hostname));
        $this->info("Admin {$email} can log in using password {$password}");

     private function tenantExists($name, $email)
        return Tenant::where('name', $name)->orWhere('email', $email)->exists();

     private function addAdmin($name, $email, $password)
        $admin = User::create(['name' => $name, 'email' => $email, 'password' => Hash::make($password)]);
        $admin->guard_name = 'web';

        return $admin;

So it can create the appropriate tenant and stuff... After all that's done i want it to redirect to tenant's subdomain... Ex: Acess Register and then redirect to or

Don't know how to do that exactly

Please sign in or create an account to participate in this conversation.