configureRateLimiting(); $this->routes(function () { // API-Routen werden global geladen Route::domain('api.' . config('app.domain') . config('app.tld_care')) ->middleware('api') ->namespace($this->namespace) ->group(base_path('routes/api.php')); // Web-Routen werden domain-bewusst geladen Route::middleware('web') ->namespace($this->namespace) ->group(function() { $this->loadDomainAwareRoutes(); }); }); } /** * Lädt Routen basierend auf dem aktuellen Domain-Kontext. */ protected function loadDomainAwareRoutes(): void { /** @var DomainContext $context */ $context = app(DomainContext::class); $this->loadSharedRoutes(); match ($context->type) { 'main' => $this->loadDomainRoutes('main', 'main.php'), 'main-shop' => [ $this->loadDomainRoutes('shop', 'shop.php'), $this->loadDomainRoutes('portal', 'portal.php'), ], 'user-shop' => [ $this->loadDomainRoutes('user-shop', 'user-shop.php'), $this->loadDomainRoutes('portal', 'portal.php'), ], 'crm' => $this->loadDomainRoutes('crm', 'crm.php'), 'portal' => $this->loadDomainRoutes('portal', 'portal.php'), 'checkout' => $this->loadDomainRoutes('checkout', 'checkout.php'), default => $this->loadAllDomainRoutesForCaching(), }; } /** * Lädt eine spezifische Routendatei für eine Domain. */ protected function loadDomainRoutes(string $domainType, string $fileName): void { $domain = config("domains.domains.{$domainType}.host"); Route::domain($domain) ->group(base_path('routes/domains/' . $fileName)); } /** * Lädt alle domainspezifischen Routen. * Wird als Fallback für das Route-Caching benötigt. */ protected function loadAllDomainRoutesForCaching(): void { if (app()->routesAreCached()) { return; } $this->loadDomainRoutes('main', 'main.php'); $this->loadDomainRoutes('shop', 'shop.php'); $this->loadDomainRoutes('crm', 'crm.php'); $this->loadDomainRoutes('portal', 'portal.php'); $this->loadDomainRoutes('checkout', 'checkout.php'); $this->loadDomainRoutes('user-shop', 'user-shop.php'); } /** * Lädt Routen, die auf allen Domains verfügbar sein sollen. */ protected function loadSharedRoutes(): void { // Lädt Routen, die auf allen Domains verfügbar sein sollen. Route::group([], base_path('routes/shared/common.php')); } /** * Konfiguriert die Rate-Limiter für die Anwendung. * * @return void */ protected function configureRateLimiting() { RateLimiter::for('api', function (Request $request) { return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip()); }); } }