File: D:/HostingSpaces/SBogers10/ste.komma.pro/app/Http/Wildcards/ProductsWildcard.php
<?php
namespace App\Http\Wildcards;
use App\Products\Models\ProductTranslation;
use Illuminate\Http\Request;
class ProductsWildcard implements WildcardInterface
{
/**
* @param Request $request
* @param string $route
* @param string $tail
* @return Request
*/
public function handle(Request $request, string $route, string $tail): Request
{
$tailParts = explode('/', $tail);
// Check if the first segment is found in the VacancyTranslation
$modelTranslation = ProductTranslation::where('language_id', app()->getLanguage()->id)
->where('slug', $tailParts[0])
->first();
// If found then send to the show method
if($modelTranslation)
{
//Set the request URI and the original path
$request->server->set('REQUEST_URI', 'products/'. $modelTranslation->product_id);
return $request;
}
return $request;
}
}