Created
April 13, 2023 15:00
-
-
Save Sharifur/eab15a572fd6e5ef77c0604964e77e15 to your computer and use it in GitHub Desktop.
fix www. count as subdomain in tenancyforlaravel package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace App\Http\Middleware\Tenant; | |
use Closure; | |
use Illuminate\Http\Request; | |
use Stancl\Tenancy\Contracts\Tenant; | |
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedByRequestDataException; | |
use Stancl\Tenancy\Middleware\IdentificationMiddleware; | |
use Stancl\Tenancy\Resolvers\DomainTenantResolver; | |
use Stancl\Tenancy\Tenancy; | |
class InitializeTenancyByDomainCustomisedMiddleware extends IdentificationMiddleware | |
{ | |
/** @var callable|null */ | |
public static $onFail; | |
/** @var Tenancy */ | |
protected $tenancy; | |
/** @var DomainTenantResolver */ | |
protected $resolver; | |
public function __construct(Tenancy $tenancy, DomainTenantResolver $resolver) | |
{ | |
$this->tenancy = $tenancy; | |
$this->resolver = $resolver; | |
} | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @return mixed | |
*/ | |
public function handle($request, Closure $next) | |
{ | |
$eploded_url = explode(".",$request->getHost()); | |
$remove_unwanted_string_from_domain_url = $request->getHost(); | |
if(current($eploded_url) === "www"){ | |
$remove_unwanted_string_from_domain_url = substr(implode(".",$eploded_url),4); | |
} | |
return $this->initializeTenancy( | |
$request, $next, $remove_unwanted_string_from_domain_url | |
); | |
} | |
} | |
//use case | |
Route::middleware([ | |
'web', | |
\App\Http\Middleware\Tenant\InitializeTenancyByDomainCustomisedMiddleware::class, | |
// InitializeTenancyByDomain::class, | |
PreventAccessFromCentralDomains::class, | |
'tenant_glvar', | |
'setlang' | |
])->group(function () { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment