@@ -64,7 +64,9 @@ public function getAll()
6464 */
6565 public function getBySlug ($ slug , $ bookId )
6666 {
67- return $ this ->page ->where ('slug ' , '= ' , $ slug )->where ('book_id ' , '= ' , $ bookId )->first ();
67+ $ page = $ this ->page ->where ('slug ' , '= ' , $ slug )->where ('book_id ' , '= ' , $ bookId )->first ();
68+ if ($ page === null ) abort (404 );
69+ return $ page ;
6870 }
6971
7072 /**
@@ -120,6 +122,7 @@ public function saveNew(array $input, Book $book, $chapterId = null)
120122 */
121123 protected function formatHtml ($ htmlText )
122124 {
125+ if ($ htmlText == '' ) return $ htmlText ;
123126 libxml_use_internal_errors (true );
124127 $ doc = new \DOMDocument ();
125128 $ doc ->loadHTML ($ htmlText );
@@ -174,11 +177,11 @@ protected function formatHtml($htmlText)
174177 */
175178 public function getBySearch ($ term , $ whereTerms = [])
176179 {
177- $ terms = explode (' ' , preg_quote ( trim ( $ term)) );
180+ $ terms = explode (' ' , $ term );
178181 $ pages = $ this ->page ->fullTextSearch (['name ' , 'text ' ], $ terms , $ whereTerms );
179182
180183 // Add highlights to page text.
181- $ words = join ('| ' , $ terms );
184+ $ words = join ('| ' , explode ( ' ' , preg_quote ( trim ( $ term ), ' / ' )) );
182185 //lookahead/behind assertions ensures cut between words
183186 $ s = '\s\x00-/:-@\[-`{-~ ' ; //character set for start/end of words
184187
0 commit comments