diff --git a/app/Http/Controllers/BlogArticleController.php b/app/Http/Controllers/BlogArticleController.php index 8ede612..f425b85 100644 --- a/app/Http/Controllers/BlogArticleController.php +++ b/app/Http/Controllers/BlogArticleController.php @@ -61,7 +61,7 @@ class BlogArticleController extends Controller public function popular() { $data = BlogArticle::select() - ->orderBy('views', 'desc') + ->orderByUniqueViews('desc') ->orderBy('date', 'desc') ->where('published', true) ->limit(5) diff --git a/database/migrations/2021_09_04_084238_remove_views_from_blog_articles.php b/database/migrations/2021_09_04_084238_remove_views_from_blog_articles.php new file mode 100644 index 0000000..cda1674 --- /dev/null +++ b/database/migrations/2021_09_04_084238_remove_views_from_blog_articles.php @@ -0,0 +1,32 @@ +dropColumn('views'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('blog_articles', function (Blueprint $table) { + $table->integer('views')->default(0); + }); + } +}