I'm currently using the route/model binding to check if there is a valid id for a Tag
in my database. It's pretty sweet so far but I would like to make sure that:
- If there is no slug set it should redirect to the slugged url
- Make sure the slug is correct (in case of update) and redirect to proper slugged url.
$router->bind('tag_id', function ($id) {
$tag = \App\Tag::getById($id);
// if ($tag->slug !== \Request::segment(3))
// {
// return redirect('/tags/' . $tag->id . '/' . $tag->slug);
// }
if ($tag instanceof \App\Tag)
{
return $tag;
}
throw new NotFoundHttpException;
});
That's my code so far, but no idea how to redirect out of the RouteServiceProvider
or if it's even possible form there. Is there anyway to do this. I know it would be quite easy for the /tags/:id
style url, but I would like to catch the incorrect slugs as well if possible.