Skip to content
This repository has been archived by the owner on Sep 10, 2019. It is now read-only.

Commit

Permalink
Adds 404 error if page not found
Browse files Browse the repository at this point in the history
  • Loading branch information
rathesDot committed Nov 2, 2017
1 parent d4cadb8 commit bbbd789
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Controllers/FrontendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Aheenam\Mozhi\RouteResolver;
use Aheenam\Mozhi\TemplateRenderer;
use Illuminate\Routing\Controller;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class FrontendController extends Controller
{
Expand All @@ -16,6 +17,8 @@ public function show($slug)
{
$page = (new RouteResolver)->getPageByRoute($slug);

if ($page === null) throw new NotFoundHttpException();

$view = (new TemplateRenderer($page))->render([]);

return response($view, 200);
Expand Down
8 changes: 8 additions & 0 deletions tests/FrontControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,12 @@ public function it_renders_correct_view_on_route()

$this->assertMatchesSnapshot($response->getContent());
}

/** @test */
public function it_returns_a_404_if_route_not_found()
{
$this->get('/not-found')
->assertStatus(404);
}

}

0 comments on commit bbbd789

Please sign in to comment.