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/SBogers10/anvil.komma.pro/app/Http/Wildcards/SegmentsWildcard.php
<?php

namespace App\Http\Wildcards;


use App\KommaApp\Segments\Models\Segment;
use App\KommaApp\Segments\Models\SegmentTranslation;

class SegmentsWildcard implements WildcardInterface
{

    /**
     * @param $request
     * @param $wildcard
     * @return mixed
     */
    public function handle($request, $wildcard)
    {

        $site = \App::getSite();


        // Check if the first segment is found in the Segment translation
        if($segmentTranslations = SegmentTranslation::where('slug', $wildcard->tail[0])
            ->where('language_id', \App::getLanguage()->id)
            ->get())
        {

            // If found loop through the found segmentTranslations and check if one
            foreach ($segmentTranslations as $segmentTranslation) {

                // If the segment doesn't belong to this site continue
                if($segmentTranslation->translatable->site->id !== $site->id) continue;

                //If it belong to this site, set the request URI and the original path
                $request->server->set('REQUEST_URI', 'segments/'.$segmentTranslation->segment_id);
                return $request;
            }
        }

        return $request;
    }

}