File: D:/HostingSpaces/Eurotools/euro-tools.nl/app/Http/Wildcards/ProductsWildcard.php
<?php
namespace App\Http\Wildcards;
use App\KommaApp\Shop\Categories\Models\CategoryTranslation;
use App\KommaApp\Shop\Products\Product\ProductTranslation;
class ProductsWildcard implements WildcardInterface
{
/**
* @param $request
* @param $wildcard
* @return mixed
*/
public function handle($request, $wildcard)
{
// only logged in users may see the product pages
if(!\Auth::check()) {
return abort(403);
}
// Check if the first segment is found in the ProductTranslation
// If ProductTranslation isn't found then send to the filters method
if($productTranslation = ProductTranslation::where('slug', $wildcard->tail[0])->first())
{
// set the language if it is not the same as the current language
$language = $productTranslation->language;
if(isset($language) && \App::getLanguage() != $language) \App::setLanguage($language);
//Set the request URI and the original path
$request->server->set('REQUEST_URI', 'products/'.$productTranslation->product_id);
return $request;
}
// Bind filters to the request and set uri to the filter function of the product controller
$request->merge(['filters' => $wildcard->tail]);
//Set the request URI and the original path
// $request->server->set('REQUEST_URI', 'products/filters');
return $request;
}
}