spatie / laravel-multitenancy

Make your Laravel app usable by multiple tenants
https://spatie.be/docs/laravel-multitenancy
MIT License
1.11k stars 153 forks source link

Middleware identification = Invalid catalog name: 1046 No database selected #141

Closed dambridge closed 4 years ago

dambridge commented 4 years ago

Completely lost on this error. I'm using a middleware (IdentifyTenant) to determine tenants like so:

    public function handle(Request $request, Closure $next)
    {
        if ($request->session()->has('current_tenant')) {

            $currentTenantId =  $request->session()->get('current_tenant');

            /** @var Tenant $tenant */
            $tenant = $this->getTenantModel()::where('id', $currentTenantId)->first();
            $tenant->makeCurrent();

            return $next($request);

        } else {

            throw new NotFoundHttpException;

        }
    }

Kernel.php:

    'tenant' => [
        \App\Http\Middleware\IdentifyTenant::class,
        \Spatie\Multitenancy\Http\Middleware\NeedsTenant::class,
        \Spatie\Multitenancy\Http\Middleware\EnsureValidTenantSession::class,
    ]

I'm not actually sure the middleware is even 'running' per se, as no dd() even works in it. I do, however, see it listed in the request stack and if I put garbage in it, it will error out as expected...

I'm using Laravel 8 with Fortify/Jetstream, and this error occurs after registration and redirection to the Dashboard

masterix21 commented 4 years ago

Hi @dambridge, your route uses Route::get(...)->middleware('tenant')?

masterix21 commented 4 years ago

I'm closing the issue because isn't related to the package, but feel free to continue the talk here ;)