diff options
| -rw-r--r-- | app/Http/Controllers/IndexController.php | 16 | ||||
| -rw-r--r-- | resources/views/list.blade.php | 12 | ||||
| -rw-r--r-- | resources/views/topicpopular.blade.php | 37 | ||||
| -rw-r--r-- | routes/web.php | 1 |
4 files changed, 66 insertions, 0 deletions
diff --git a/app/Http/Controllers/IndexController.php b/app/Http/Controllers/IndexController.php index cb401b5..bb1d301 100644 --- a/app/Http/Controllers/IndexController.php +++ b/app/Http/Controllers/IndexController.php @@ -104,4 +104,20 @@ class IndexController extends Controller return view('list', ["articles" => $articles, "count" => $count]); } + + public function populartopics() { + $topics = DB::select(" + SELECT + c.name, + count(c.name) AS count + FROM category AS c + JOIN + article_category AS ac ON c.id = ac.category_id + GROUP BY + c.name + ORDER BY count(c.name) DESC;"); +#echo "<pre>"; var_dump($topics);exit; + + return view('topicpopular', ['topics' => $topics ]); + } } diff --git a/resources/views/list.blade.php b/resources/views/list.blade.php index f47c28a..1f6fc72 100644 --- a/resources/views/list.blade.php +++ b/resources/views/list.blade.php @@ -53,6 +53,10 @@ html { <div class="card-body"> <p class="card-text"> You are looking at all articles with the topic <strong>"{{ Request::route()->parameters()["topic"] }}"</strong>. We found {{ $count }} matches. + <br> + <br> + <strong>Hint:</strong> + <em>To view all topics, <a href="{{ route('topic_index') }}" title="all topics">click here</a>. Too see the most popular topics, <a href="{{ route('popular_topics') }}" title="popular topics">click here instead</a>.</em> </p> </div> @elseif ( "random" == Request::route()->getName() ) @@ -79,6 +83,14 @@ html { </a> </div> </h1> + @if ( "popular" == Request::route()->getName() ) + <div class="card-body"> + <p class="card-text"> + <strong>Hint:</strong> + <em>You are looking at the most popular articles. If you are interested in popular topics instead, <a href="{{ route('popular_topics') }}" title="popular topics">click here</a>.</em> + </p> + </div> + @endif @endif </div> diff --git a/resources/views/topicpopular.blade.php b/resources/views/topicpopular.blade.php new file mode 100644 index 0000000..f6a2c8a --- /dev/null +++ b/resources/views/topicpopular.blade.php @@ -0,0 +1,37 @@ +@extends ('layouts.app') + +@section ('styles') +html { + height: inherit; +} +@endsection + +@section ('content') + +<div class="container"> + + <div style="margin-top: 20px"></div> + <div class="card"> + <h1 class="card-header"> + Popular Topics + </h1> + <div class="card-body"> + <p class="card-text"> + <strong>Hint:</strong> <em>You are looking at popular topics. If you are interested in the most popular articles instead, <a href="{{ route('popular') }}" alt="popular articles">click here instead</a>.</em> + </p> + </div> + </div> + <div style="margin-bottom: 20px"></div> + + <div class="text-center card"> + <div class="card-body"> + @foreach ($topics as $topic) + @if ( "" != $topic->name ) + <a href="{{ route('topic', $topic->name) }}" class="btn btn-lg btn-primary mx-1 my-1">{{ ucwords($topic->name) }} ({{ $topic->count }} Articles)</a> + @endif + @endforeach + </div> + </div> + +</div> +@endsection diff --git a/routes/web.php b/routes/web.php index 79615a6..a45dc59 100644 --- a/routes/web.php +++ b/routes/web.php @@ -18,6 +18,7 @@ Route::get('/topic/{topic}', 'IndexController@topic')->name('topic')->where('top Route::get('/topic/', 'IndexController@topicindex')->name('topic_index'); Route::get('/new', 'IndexController@new')->name('new'); Route::get('/search', 'IndexController@search')->name('search'); +Route::get('/popular/topics', 'IndexController@populartopics')->name('popular_topics'); Route::get('/popular', 'IndexController@popular')->name('popular'); Route::get('/random', 'IndexController@random')->name('random'); |
