File: D:/HostingSpaces/SBogers95/rentman.io/app/Http/Wildcards/PostsWildcard.php
<?php
namespace App\Http\Wildcards;
use App\Komma\Posts\Models\PostTranslation;
class PostsWildcard implements WildcardInterface
{
/**
* @param $request
* @param $wildcard
* @return mixed
*/
public function handle($request, $wildcard)
{
// Check if the first segment is found in the PostTranslation
// If PostTranslation isn't found then send to the filters method
if (count($wildcard->tail) == 1 && $postTranslation = PostTranslation::where('slug', $wildcard->tail[0])->first()) {
//Set the request URI and the original path
$request->server->set('REQUEST_URI', 'posts/'.$postTranslation->post_id);
return $request;
}
if(count($wildcard->tail) == 1 && in_array(ucfirst($wildcard->tail[0]), __('postCategories.categories'))){
//Set the request URI and the original path
$request->server->set('REQUEST_URI', 'posts/category/'.$wildcard->tail[0]);
return $request;
}
return $request;
}
}