File: D:/HostingSpaces/Anvil/anvil-industries.com/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 !== 'anvil' && $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;
}
}