File: D:/HostingSpaces/netwerkbrabant/netwerkbrabant.nl/app/Http/Wildcards/PastEventsWildcard.php
<?php
namespace App\Http\Wildcards;
use App\KommaApp\PastEvents\Models\PastEventTranslation;
use App\KommaApp\Regions\Models\Region;
class PastEventsWildcard implements WildcardInterface
{
/**
* @param $request
* @param $wildcard
* @return mixed
*/
public function handle($request, $wildcard)
{
// Check if the first segment is found in the PostTranslation
// If PostTranslation isn't found then send to the filters method
if($pastEventTranslation = PastEventTranslation::where('slug', $wildcard->tail[0])->first())
{
//Set the request URI and the original path
$request->server->set('REQUEST_URI', 'pastevents/'.$pastEventTranslation->past_event_id);
return $request;
}
if(sizeof($wildcard->tail) == 1 && $wildcard->tail[0] == 'regio')
{
$request->server->set('REQUEST_URI', 'pastevents/region');
$request->merge(['redirect' => $wildcard->type->alias ]);
return $request;
}
if($region = Region::where('slug', $wildcard->tail[0])->first()){
//Set the request URI and the original path
$request->server->set('REQUEST_URI', 'pastevents/region/'.$region->id);
return $request;
}
// Bind filters to the request and set uri to the filter function of the post controller
$request->merge(['filters' => $wildcard->tail]);
//Set the request URI and the original path
$request->server->set('REQUEST_URI', 'pastevents/filters');
return $request;
}
}