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;
}
}