Browse Source

文章页优化

moell 8 years ago
parent
commit
d3ec2b595f

+ 4 - 11
app/Http/Controllers/ArticleController.php

@@ -19,16 +19,9 @@ class ArticleController extends Controller
 
     public function index($id)
     {
-        try {
-            $article = $this->article->find($id);
-            $category = $article->category;
-            $tags = $article->tag;
-            $user = $article->user;
-            $update['read_count'] = $article->read_count + 1;
-            $this->article->update($update, $id);
-            return view('default.show_article', compact('article', 'category', 'tags', 'user'));
-        } catch (\Exception $e) {
-            die($e->getMessage());
-        }
+        $article = $this->article->find($id);
+        $article->read_count = $article->read_count + 1;
+        $article->save();
+        return view('default.show_article', compact('article'));
     }
 }

+ 7 - 5
resources/views/default/show_article.blade.php

@@ -24,14 +24,16 @@
                 <p class=" m-t-25 color-white">
                     <i class="glyphicon glyphicon-calendar"></i>{{ $article->created_at }}
                     &nbsp;
-                    <i class="glyphicon glyphicon-th-list"></i>
-                    <a href="{{ route('category', ['id' => $category->id]) }}" target="_blank">
-                        {{ $category->name }}
-                    </a>
+                    @if($article->category)
+                        <i class="glyphicon glyphicon-th-list"></i>
+                        <a href="{{ route('category', ['id' => $article->cate_id]) }}" target="_blank">
+                            {{ $article->category->name }}
+                        </a>
+                    @endif
                 </p>
                 <p class="color-white">
                     <i class="glyphicon glyphicon-tags"></i>&nbsp;
-                    @foreach ($tags as $tag)
+                    @foreach ($article->tag as $tag)
                         <a href="{{ route('tag', ['id' => $tag->id]) }}" target="_blank">
                             {{ $tag->tag_name }}
                         </a>