File: D:/HostingSpaces/SBogers10/shop.komma.nl/app/Http/Wildcards/CategoriesWildcard.php
<?php
namespace App\Http\Wildcards;
use App\Categories\Kms\CategoryTreeService;
use Illuminate\Http\Request;
class CategoriesWildcard implements WildcardInterface
{
/**
* @param Request $request
* @param string $route
* @param string $tail
* @return Request
*/
public function handle(Request $request, string $route, string $tail): Request
{
$categoryTreeService = new CategoryTreeService();
// Check if the first segment is found in the ProductTranslation
// If ProductTranslation isn't found then send to the filters method
$rootWithTranslations = $categoryTreeService->treeWithTranslationsLinksAndActiveStates();
$breadcrumbStack = $categoryTreeService->breadcrumbToStack($rootWithTranslations, $tail);
$lastCategory = last($breadcrumbStack);
if($lastCategory) {
//Set the request URI and the original path
$request->server->set('REQUEST_URI', 'categories/'.$lastCategory->id);
return $request;
}
return $request;
}
}