Browse Source

Controller code optimization

moell 8 years ago
parent
commit
7fcfefabcd

+ 6 - 10
app/Http/Controllers/CategoryController.php

@@ -18,15 +18,11 @@ class CategoryController extends Controller
 
     public function index($id)
     {
-        try {
-            $category = $this->category->baseFind($id);
-            $articles = $category->article()
-                ->orderBy('sort','desc')
-                ->orderBy('id', 'desc')
-                ->paginate(15);
-            return view('default.category_article', compact('articles', 'category'));
-        } catch (\Exception $e) {
-            return redirect('/');
-        }
+        $category = $this->category->find($id);
+        $articles = $category->article()
+            ->orderBy('sort','desc')
+            ->orderBy('id', 'desc')
+            ->paginate(15);
+        return view('default.category_article', compact('articles', 'category'));
     }
 }

+ 1 - 2
app/Http/Controllers/SearchController.php

@@ -11,8 +11,7 @@ class SearchController extends Controller
 {
     public function index(Request $request, ArticleRepositoryEloquent $articleRepo)
     {
-        $keyword = $request->keyword;
         $articles = $articleRepo->searchKeywordArticle($request->keyword);
-        return view('default.search_article', compact('articles', 'keyword'));
+        return view('default.search_article', compact('articles'));
     }
 }

+ 6 - 10
app/Http/Controllers/TagController.php

@@ -19,15 +19,11 @@ class TagController extends Controller
 
     public function index($id)
     {
-        try {
-            $tag = $this->tag->find($id);
-            $articles = $tag->article()
-                ->orderBy('sort','desc')
-                ->orderBy('id', 'desc')
-                ->paginate(15);
-            return view('default.tag_article', compact('articles', 'tag'));
-        } catch (\Exception $e) {
-            die($e->getMessage());
-        }
+        $tag = $this->tag->find($id);
+        $articles = $tag->article()
+            ->orderBy('sort','desc')
+            ->orderBy('id', 'desc')
+            ->paginate(15);
+        return view('default.tag_article', compact('articles', 'tag'));
     }
 }

+ 7 - 1
app/Presenters/ArticlePresenter.php

@@ -38,7 +38,13 @@ class ArticlePresenter extends FractalPresenter
      */
     public function hotArticleList()
     {
-        return $this->article->orderBy('read_count', 'desc')->paginate(5, ['id', 'title']);
+        return $this->article
+            ->orderBy('read_count', 'desc')
+            ->paginate(5, [
+                'id',
+                'title',
+                'read_count'
+            ]);
     }
 
     public function formatTitle($title)

+ 0 - 19
app/Repositories/CategoryRepositoryEloquent.php

@@ -91,25 +91,6 @@ class CategoryRepositoryEloquent extends BaseRepository implements CategoryRepos
         return true;
     }
 
-    /**
-     * @param $id
-     * @param array $columns
-     * @return mixed
-     */
-    public function find($id, $columns = ['*'])
-    {
-        $this->applyCriteria();
-        $this->applyScope();
-        $model = $this->model->find($id, $columns);
-        $this->resetModel();
-
-        return $this->parserResult($model);
-    }
-
-    public function baseFind($id, $columns = ['*'])
-    {
-        return parent::find($id, $columns);
-    }
 
     /**
      * Boot up the repository, pushing criteria

+ 1 - 3
public/default/css/index.css

@@ -18,7 +18,6 @@
     background-color: transparent;
 }
 
-
 .navbar-static-top {
     border-width: 0 0 0;
 }
@@ -59,7 +58,6 @@
 
 .article-list .info {
     margin-top:25px;
-    color:#3D93A3;
 }
 .icon-github {
     background: url('/default/icons/github.png') no-repeat;
@@ -92,5 +90,5 @@
 
 
 a {
-    color: #34495e;
+    color:#3D93A3;
 }

+ 1 - 0
resources/views/default/hot.blade.php

@@ -10,6 +10,7 @@
         @if ($hotArticleList)
             @foreach ($hotArticleList as $hal)
                 <li class="list-group-item">
+                    <span class="badge">{{ $hal->read_count }}</span>
                     <a href="{{ route('article', ['id' => $hal->id]) }}" target="_blank">
                         {{ $hotArticle->formatTitle($hal->title) }}
                     </a>

+ 4 - 4
resources/views/default/search_article.blade.php

@@ -1,10 +1,10 @@
 @extends('layouts.app')
 
-@section('title', $keyword)
+@section('title', request('keyword'))
 
-@section('description', $keyword)
+@section('description', request('keyword'))
 
-@section('keywords', $keyword)
+@section('keywords', request('keyword'))
 
 @section('header-text')
     <div class="text-inner">
@@ -13,7 +13,7 @@
                 <h3 class="to-animate fadeInUp animated color-white">
                     <i class="glyphicon glyphicon-search"></i>
                     &nbsp;
-                    {{ $keyword }}
+                    {{ request('keyword') }}
                 </h3>
             </div>
         </div>