@@ -74,6 +74,21 @@ function cutstr_html($string)
7474 //文章详情
7575 public function show (Request $ request , $ id )
7676 {
77+ $ articleIdArr = array_column (Article::select (['id ' ])->where ('is_hidden ' , 0 )->orderBy ('is_top ' , 'desc ' )->orderBy ('created_at ' , 'desc ' )->get ()->toArray (), 'id ' );
78+ $ currId = array_search ($ id , $ articleIdArr );
79+
80+ if (!isset ($ articleIdArr [$ currId - 1 ])) {
81+ $ preId = '' ;
82+ } else {
83+ $ preId = $ articleIdArr [$ currId - 1 ];
84+ }
85+
86+ if (!isset ($ articleIdArr [$ currId + 1 ])) {
87+ $ bacId = '' ;
88+ } else {
89+ $ bacId = $ articleIdArr [$ currId + 1 ];
90+ }
91+
7792 $ articleCount = Article::all ()->count ();
7893 $ catesCount = Cate::all ()->count ();
7994 $ tagsCount = Tag::all ()->count ();
@@ -83,8 +98,8 @@ public function show(Request $request, $id)
8398 $ article ->updated_at_date = $ article ->updated_at ->toDateString ();
8499 $ comments = $ article ->comments ()->where ('parent_id ' , 0 )->orderBy ('created_at ' , 'desc ' )->get ();
85100 $ field = 'id, title ' ;
86- $ preArticle = Article::select (DB :: RAW ( " $ field " ))-> where ( ' is_hidden ' , 0 )-> where ( ' id ' , '< ' , $ id )->orderBy ('id ' , ' desc ' )->first (); //->orderBy('is_top', 'desc')->orderBy('created_at', 'desc')
87- $ bacArticle = Article::select (DB :: RAW ( " $ field " ))-> where ( ' is_hidden ' , 0 )-> where ( ' id ' , '> ' , $ id )->orderBy ('id ' , ' asc ' )->first (); //->orderBy('is_top', 'desc')->orderBy('created_at', 'desc')
101+ $ preArticle = Article::select ([ ' id ' , 'title ' ] )->where ('id ' , $ preId )->first ();
102+ $ bacArticle = Article::select ([ ' id ' , 'title ' ] )->where ('id ' , $ bacId )->first ();
88103 $ count = $ article ->comments ()->count ();
89104 $ article ->words = mb_strlen (strip_tags ($ article ->content_html ), 'UTF8 ' );
90105 $ article ->read = ceil ($ article ->words / 1000 );
0 commit comments