Route parameters in TenantFinder #455
-
Hello, I have an application prior to using your package, where I use route middleware to determine the current tenant based on route parameters. This middleware is called before I am currently trying to adopt this package. Inside my Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I got this to work by allowing my <?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Application;
use Illuminate\Http\Request;
use Spatie\Multitenancy\TenantFinder\TenantFinder;
readonly class SetCurrentTenant
{
public function __construct(private Application $app)
{
}
public function handle(Request $request, \Closure $next)
{
$tenant = $this->app[TenantFinder::class]->findForRequest($request);
$tenant?->makeCurrent();
return $next($request);
}
} |
Beta Was this translation helpful? Give feedback.
I got this to work by allowing my
TenantFinder
to returnnull
when$request->route()
is empty, then re-attempting thefindForRequest()
in a route middleware: