123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- namespace App\Http\Middleware;
- use Closure;
- use Illuminate\Http\Request;
- use Symfony\Component\HttpFoundation\Response;
- use App\Helpers\SiteCache;
- /**
- * Class LoadDistData 用中间件来获取distm网店信息
- */
- class LoadDistData
- {
- /**
- * Handle an incoming request.
- *
- * @param
- */
- public function handle(Request $request, Closure $next): Response
- {
- // 获取请求的域名
- $domain = getHost();
- // 先检查 custom_domain,如果没有找到,再检查 secondary_domain
- $dist=SiteCache::getDist($domain);
- // 如果找不到匹配的数据,直接返回404响应
- if (!$dist) {
- abort(404, 'site not found.');
- }
- // 将找到的 dist 数据添加到请求中,方便后续使用
- $request->attributes->set('dist', $dist);
- //保存到共享地方供其它地方用
- return $next($request);
- }
- }
|