group(...) * Route::middleware('domain:docs.lthn.io,docs.test')->group(...) */ class DomainScope { public function handle(Request $request, Closure $next, string ...$domains): mixed { $host = $request->getHost(); foreach ($domains as $domain) { // Exact match if ($host === $domain) { return $next($request); } // Wildcard match (e.g., *.lthn.io) if (str_starts_with($domain, '*.')) { $suffix = substr($domain, 1); // .lthn.io if (str_ends_with($host, $suffix)) { return $next($request); } } } abort(404); } }