29 files changed
+94
-881
No files matched your search
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Models\Business;
|
||||
use App\Models\BusinessDomain;
|
||||
use App\Services\Tenant\TenantContext;
|
||||
use App\Services\Tenant\DomainNormalizer;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
@@ -14,25 +14,26 @@ class ResolveTenant
|
||||
{
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
$hostname = null;
|
||||
$hostname = strtolower(rtrim($request->getHost(), '.'));
|
||||
try {
|
||||
$hostname = app(DomainNormalizer::class)->normalize($request->getHost());
|
||||
$business = BusinessDomain::query()
|
||||
->where('hostname', $hostname)
|
||||
->where('isActive', true)
|
||||
->with('business')
|
||||
->first()?->business;
|
||||
|
||||
if (! $business && app()->environment('local')) {
|
||||
$slug = config('app.default_business_slug');
|
||||
$business = $slug
|
||||
? Business::query()->where('slug', $slug)->first()
|
||||
: null;
|
||||
}
|
||||
} catch (Throwable) {
|
||||
// The install page and framework smoke tests must remain
|
||||
// reachable before the tenant schema has been created.
|
||||
$business = null;
|
||||
}
|
||||
|
||||
if (! $business) {
|
||||
app(TenantContext::class)->forget();
|
||||
}
|
||||
|
||||
if ($business) {
|
||||
app(TenantContext::class)->set($business);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user