99class ResourceController extends Controller
1010{
1111 // is requested slug relevant to post or page?
12- public function show ($ request )
12+ public function show ($ slug )
1313 {
14- if ( Post::where ('slug ' , $ request )-> exists ()) {
15- $ resource = Post:: where ( ' slug ' , $ request )
16- -> with ( ' tagged ' )
17- -> withCount ( ' comments ' )
18- -> first ();
14+ $ resource = Post::where ('slug ' , $ slug )
15+ -> with ( ' tagged ' )
16+ -> withCount ( ' comments ' )
17+ -> first ();
18+ if ( $ resource ) {
1919 return $ this ->showPost ($ resource );
2020 }
2121
22- if ( Page::where ('slug ' , $ request )-> exists ()) {
23- $ resource = Page:: where ( ' slug ' , $ request )
24- -> first ();
22+ $ resource = Page::where ('slug ' , $ slug )
23+ -> first ();
24+ if ( $ resource ) {
2525 return $ this ->showPage ($ resource );
2626 }
2727
2828 // if there is no resource with that slug
29- return abort ('404 ' );
29+ abort ('404 ' );
3030 }
3131
32- public function showPost ($ resource )
32+ private function showPost ($ resource )
3333 {
3434 $ next = Post::select (['slug ' ])
3535 ->where ('id ' , '> ' , $ resource ->id )
@@ -41,29 +41,28 @@ public function showPost($resource)
4141 ->published ()
4242 ->latest ('id ' )
4343 ->first ();
44-
4544 $ comments = $ resource ->comments ()
4645 ->with ('user ' )
4746 ->paginate (50 )
4847 ->onEachSide (1 );
4948
5049 // view for custom template
5150 if ($ resource ->custom_template ) {
52- return view ('frontend.posts.single-custom ' , compact ('resource ' ,'comments ' , 'next ' , 'prev ' ));
51+ return view ('frontend.posts.single-custom ' , compact ('resource ' , 'comments ' , 'next ' , 'prev ' ));
5352 }
5453 // view for default template
55- return view ('frontend.posts.single ' , compact ('resource ' ,'comments ' ,'next ' , 'prev ' ));
54+ return view ('frontend.posts.single ' , compact ('resource ' , 'comments ' , 'next ' , 'prev ' ));
5655 }
5756
58- public function showPage ($ resource )
57+ private function showPage ($ resource )
5958 {
6059 // view for custom template
6160 if ($ resource ->custom_template ) {
6261 // for common templates
6362 $ next = null ;
6463 $ prev = null ;
6564 $ comments = null ;
66- return view ('frontend.pages.single-custom ' , compact ('resource ' ,'comments ' , 'next ' , 'prev ' ));
65+ return view ('frontend.pages.single-custom ' , compact ('resource ' , 'comments ' , 'next ' , 'prev ' ));
6766 }
6867 // view for default template
6968 return view ('frontend.pages.single ' , compact ('resource ' ));
0 commit comments