From 05c4b2089c472006c8d28f88b965133b0fabfa54 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Mon, 28 Dec 2015 17:19:23 +0000 Subject: [PATCH] Accounted for non-existant entities --- app/Repos/BookRepo.php | 4 +++- app/Repos/ChapterRepo.php | 4 +++- app/Repos/PageRepo.php | 4 +++- resources/views/errors/404.blade.php | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/Repos/BookRepo.php b/app/Repos/BookRepo.php index 469fdb31d..031e3b44c 100644 --- a/app/Repos/BookRepo.php +++ b/app/Repos/BookRepo.php @@ -95,7 +95,9 @@ class BookRepo */ public function getBySlug($slug) { - return $this->book->where('slug', '=', $slug)->first(); + $book = $this->book->where('slug', '=', $slug)->first(); + if ($book === null) abort(404); + return $book; } /** diff --git a/app/Repos/ChapterRepo.php b/app/Repos/ChapterRepo.php index c3d75ca9d..1e4996a40 100644 --- a/app/Repos/ChapterRepo.php +++ b/app/Repos/ChapterRepo.php @@ -56,7 +56,9 @@ class ChapterRepo */ public function getBySlug($slug, $bookId) { - return $this->chapter->where('slug', '=', $slug)->where('book_id', '=', $bookId)->first(); + $chapter = $this->chapter->where('slug', '=', $slug)->where('book_id', '=', $bookId)->first(); + if ($chapter === null) abort(404); + return $chapter; } /** diff --git a/app/Repos/PageRepo.php b/app/Repos/PageRepo.php index 052d9dd1e..e049ae57b 100644 --- a/app/Repos/PageRepo.php +++ b/app/Repos/PageRepo.php @@ -64,7 +64,9 @@ class PageRepo */ public function getBySlug($slug, $bookId) { - return $this->page->where('slug', '=', $slug)->where('book_id', '=', $bookId)->first(); + $page = $this->page->where('slug', '=', $slug)->where('book_id', '=', $bookId)->first(); + if ($page === null) abort(404); + return $page; } /** diff --git a/resources/views/errors/404.blade.php b/resources/views/errors/404.blade.php index 8f66e2d01..0062bb258 100644 --- a/resources/views/errors/404.blade.php +++ b/resources/views/errors/404.blade.php @@ -1,9 +1,11 @@ -@extends('public') +@extends('base') @section('content') +

Page Not Found

The page you were looking for could not be found.

+
@stop \ No newline at end of file