-
I have implemented the simplest example using the Spatie docs for multitenancy, that is working perfectly fine. Now, I intend to use multiple second-level domains for each tenant I have. For example; I have 2 tenants I have tried using
Without subdomain, it works fine, but the routes with second-level domain, it falls to base level domain route and does not get the current tenant. Thankyou. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
I've done something similar modifying DomainTenantFinder and without Route:domain. |
Beta Was this translation helpful? Give feedback.
-
I have achieved this by using some checks, in
In my
As In my scenario, I had only these 2 kind of second-level domains and so, I just checked if this particular keyword exists in the hostname and choosing the file and middleware accordingly. I also overrided the
I have acheived the desired outcome, however, I have a security concern, specially in |
Beta Was this translation helpful? Give feedback.
-
Even simple answer, just simply extending the DomainTenantFinder add the findForRequest method and add in one line. <?php
namespace App\Multitenancy;
use Illuminate\Http\Request;
use Spatie\Multitenancy\Models\Tenant;
use \Spatie\Multitenancy\TenantFinder\DomainTenantFinder as TenantFinder;
class DomainTenantFinder extends TenantFinder
{
public function findForRequest(Request $request): ?Tenant
{
$host = $request->getHost();
$host = (str_contains($host,'admin.'))?str_replace('admin.', '', $host):$host;
return $this->getTenantModel()::whereDomain($host)->first();
}
} |
Beta Was this translation helpful? Give feedback.
I have achieved this by using some checks, in
RouteServiceProvider
, I have not used the actualdomain
function onRoute
like we do normally i.e.Route::domain('foo.bar')
. The reason was that, theSpatie
package use a kind of middlewareSpatie\Multitenancy\TenantFinder\DomainTenantFinder::class
which runs whenever we hit the domain with tenantcomapny-a.localhost
. And it gets the tenant from hostname i.ecomapny-a.localhost
.In my
RouteServiceProvide
: