Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

arsalan_ahmed_siddique's avatar

Multitenancy with subdomain : Undefined variable $errors and Session store not set on request on tenant login and register page

I am implementing a multi-tenant Laravel application using archtechx/tenancy package. I have set up separate databases for each tenant and have created a Tenant model to manage tenants. I am using the central database to store information about tenants and their assigned modules.

I am facing two errors on my login page:

  • Undefined variable $errors
  • Session store not set on request.

Here's what I have tried so far:

  • I have set the SESSION_DOMAIN value in my .env file to .localhost:8000
  • I have set the SESSION_DRIVER to the database in my config/session.php file.

One more thing I try, I remove all the errors variable from register.balde file and submit the form then I receive them in my central database but when I get users from UserController they are using the right tenant Database.

here is my tenant.php

Auth::routes();
Route::middleware([
    'web',
    'auth',
    InitializeTenancyByDomain::class,
    PreventAccessFromCentralDomains::class,
    CheckModuleMiddleware::class,
])->group(function () {
    Route::get('/', function () {
        // dd(\App\Models\User::all());
        return 'This is your multi-tenant application. The id of the current tenant is ' . tenant('id');
    });

    Route::resource('users', App\Http\Controllers\UserController::class);
});

Despite these efforts, I am still facing the same errors. Can anyone suggest what could be causing these errors and how to fix them?

0 likes
2 replies
LaryAI's avatar
Level 58

It looks like you are missing the Session::start() call in your UserController. This is necessary to start the session and set the session store.

You can add the following code to the __construct() method of your UserController:

public function __construct()
{
    Session::start();
}

This should resolve the Session store not set on request error.

For the Undefined variable $errors error, you can add the following code to the register.blade.php file:

@if ($errors->any())
    <div class="alert alert-danger">
        <ul>
            @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
@endif

This should resolve the Undefined variable $errors error.

Hope this helps!

ARKHAN's avatar

why you need the auth while getting the tenant. first get the tenant and they on the login routes you need the auth and on the rest of the endpoints/urls so for that i think you can apply the auth in the lower section first initiate the tenancy then auth services

Please or to participate in this conversation.