HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers95/rentman.io/app/Http/Middleware/SiteSlugResolver.php
<?php

namespace App\Http\Middleware;

use App\Komma\Sites\SiteServiceInterface;

/**
 * Class FrontendSitesResolver
 *
 * Does set the current site depending on the host / domain name using the site config file.
 */
final class SiteSlugResolver
{
    /** @var SiteServiceInterface */
    private $siteService;

    /**
     * SlugSitesResolver constructor.
     * @param SiteServiceInterface $siteService.
     */
    public function __construct(SiteServiceInterface $siteService)
    {
        $this->siteService = $siteService;
    }

    /**
     * Set site on Application.k
     *
     * @param \Illuminate\Http\Request $request
     * @param \Closure $next
     * @return mixed
     */
    public function handle($request, \Closure $next)
    {
        if (! $request->route()) {
            throw new \RuntimeException('Could not get the route of the request. Perhaps you\'re using the middleware in global middleware instead of rout middleware. Route is never availble in global middleware due to architectural concerns');
        }

        $siteSlug = $request->route('siteSlug');

        $this->siteService->setCurrentSiteBySlug($siteSlug);

        //Don't bother the rest of the application with the siteSlug parameter
        $request->route()->forgetParameter('siteSlug');

        //Return the Request, and check the other routes
        return $next($request);
    }
}