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/lc-hydraulics.komma.nl/app/Http/Wildcards/VacanciesWildcard.php
<?php

namespace App\Http\Wildcards;




use App\KommaApp\Vacancies\Models\VacancyTranslation;

class VacanciesWildcard 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($vacancyTranslations = VacancyTranslation::where('slug', $wildcard->tail[0])
            ->where('language_id', \App::getLanguage()->id)
            ->get())
        {

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

                // If the segment doesn't belong to this site continue
                if($site->slug !== 'lacom' && $vacancyTranslation->translatable->sites->where('id', $site->id)->isEmpty()) continue;

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

        return $request;
    }

}