Skip to content

Can we use multiple second-level domains with multitenancy? #372

Answered by iabduul7
iabduul7 asked this question in Q&A
Discussion options

You must be logged in to vote

I have achieved this by using some checks, in RouteServiceProvider, I have not used the actual domain function on Route like we do normally i.e. Route::domain('foo.bar'). The reason was that, the Spatie package use a kind of middleware Spatie\Multitenancy\TenantFinder\DomainTenantFinder::class which runs whenever we hit the domain with tenant comapny-a.localhost. And it gets the tenant from hostname i.e comapny-a.localhost.

    public function findForRequest(Request $request):?Tenant
    {
        $host = $request->getHost();
        return $this->getTenantModel()::whereDomain($host)->first();
    }

In my RouteServiceProvide:

     $this->routes(function () {
         $class = 'security';…

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@rsenses
Comment options

@iabduul7
Comment options

@iabduul7
Comment options

Answer selected by iabduul7
Comment options

You must be logged in to vote
2 replies
@MattWiseParking
Comment options

@MattWiseParking
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants