File: D:/HostingSpaces/netwerkbrabant/netwerkbrabant.nl/app/Http/Wildcards/ProductsWildcard.php
<?php
namespace App\Http\Wildcards;
use App\KommaApp\Events\Models\EventTranslation;
use App\KommaApp\Products\Models\ProductTranslation;
class ProductsWildcard implements WildcardInterface
{
/**
* @param $request
* @param $wildcard
* @return mixed
*/
public function handle($request, $wildcard)
{
// Check if the first segment is found in the ProductTranslation
// If ProductTranslation isn't found then send to the filters method
if(sizeof($wildcard->tail) == 1 && $productTranslation = ProductTranslation::where('slug', $wildcard->tail[0])->first())
{
//Set the request URI and the original path
$request->server->set('REQUEST_URI', 'products/'.$productTranslation->product_id);
return $request;
}
if(sizeof($wildcard->tail) == 2 && $wildcard->tail[0] == __('site/routes.products.success') && $productTranslation = ProductTranslation::where('slug', $wildcard->tail[1])->first())
{
//Set the request URI and the original path
$request->server->set('REQUEST_URI', 'products/'.$productTranslation->product_id.'/success');
return $request;
}
return $request;
}
}