File: D:/HostingSpaces/SBogers10/blije-gasten.komma.pro/app/Http/Wildcards/CategoriesWildcard.php
<?php
namespace App\Http\Wildcards;
use App\Komma\Shop\Categories\Models\CategoryTranslation;
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
{
$tailParts = explode('/', $tail);
foreach ($tailParts as $key => $tailPart) {
// Check if the first segment is found in the PostTranslation
// If PostTranslation isn't found then send to the filters method
if ($categoryTranslation = CategoryTranslation::where('slug', $tailPart)->first()) {
//Set the request URI and the original path
if($key < count($tailParts)) {
// Bind filters to the request and set uri to the filter function of the post controller
$request->merge(['filters' => array_slice($tailParts, $key+1)]);
}
$request->server->set('REQUEST_URI', 'categories/' . $categoryTranslation->category_id);
return $request;
}
}
return $request;
}
}