Laravel 4: using controller to redirect page if post does not exist - tried but failed so far
问题 I'm working with Laravel 4, I have a page that shows posts e.g. example.com/posts/1 shows the first post from the db. What I want to do is redirect the page to the index if someone tries to go to a url that doesn't exist. e.g. if there was no post number 6 then example.com/posts/6 should redirect to example.com/posts Here is what I have, is it on track at all? public function show($id) { $post = $this->post->findOrFail($id); if($post != NULL) { return View::make('posts.show', compact('post'))