Display Popular Posts – WordPress-Like Blog Laravel 5.7 and AdminLTE 3 (8)

WordPress-Like Blog Laravel 5.7 and AdminLTE 3 (8) – Display Popular Posts

In this eighth part of creating WordPress-Like Blog using Laravel 5.6/5.7 and AdminLTE 3, we will :

  1. Create view_count column on the posts table
  2. Display popular posts widget on the sidebar
  3. Increment the displayed post by 1

Create view_count column on the posts table

The basic concept of the popular post, if a post is being opened, the counter will be incremented by 1. So we need to create a new column to store information how many has one post is displayed.

Create new migration :

Run the migration : php artisan migrate

Add the view_count seed to PostsTableSeeder.php

Run the seeder : php artisan db:seed

Open Post model and add scopePopular() and image_thumb_url() method :

Display popular posts widget on the sidebar

Open layouts/sidebar.blade.php and add the following code :

Modify ComposerServiceProvider.php to add the posts, don’t forget to add use App\Post

Open the project url, now you will find the popular posts widget on the sidebar :

Membuat Blog dengan Laravel 5.7 dan AdminLTE 3 (8) – Menampilkan Popular Posts

Increment the displayed post by 1

Modify BlogController the show() method :

Ok, now our popular post has worked. However, before we end this part, let’s refactor the ComposerServiceProvider.php .

First, we create View folder in the app directory, and create Composers folder within that directory. We will put the view composer to this folder. Create a new file, NavigationComposer.php

And modify the ComposerServiceProvider.php

Don’t forget to add namespace :

Ok, done!

Github Commit.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.