From 57a8fc58d61d3ed5fcba6a3548918eb78eb3472c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Thu, 16 Aug 2018 22:30:46 +0200 Subject: [PATCH] add Longest and Shortest filters --- app/Http/Controllers/DashController.php | 12 ++++++++++++ app/Models/Table.php | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/DashController.php b/app/Http/Controllers/DashController.php index 3ff3c00..97b1366 100644 --- a/app/Http/Controllers/DashController.php +++ b/app/Http/Controllers/DashController.php @@ -30,6 +30,8 @@ class DashController extends Controller // 'most-liked' => 'Most Liked', 'newest' => 'Newest', 'oldest' => 'Oldest', + 'most-rows' => 'Longest', + 'least-rows' => 'Shortest', ]; $data['users'] = User::orderBy('updated_at', 'desc') @@ -54,6 +56,16 @@ class DashController extends Controller case 'most-liked': $tableQuery = $tableQuery->orderBy('favourites_count', 'desc'); break; + case 'most-rows': + $tableQuery = $tableQuery + ->join('revisions', 'revisions.id', '=', 'tables.revision_id') + ->orderBy('revisions.row_count', 'desc'); + break; + case 'least-rows': + $tableQuery = $tableQuery + ->join('revisions', 'revisions.id', '=', 'tables.revision_id') + ->orderBy('revisions.row_count', 'asc'); + break; case 'newest': $tableQuery = $tableQuery->orderBy('created_at', 'desc'); break; diff --git a/app/Models/Table.php b/app/Models/Table.php index c45e13b..3d0cb83 100644 --- a/app/Models/Table.php +++ b/app/Models/Table.php @@ -188,7 +188,8 @@ class Table extends BaseModel public function scopeForList(Builder $query) { - return $query->with('revision:id,row_count')->with('owner:id,name,title') + return $query->with('revision:id,row_count') + ->with('owner:id,name,title') ->withCount(['favourites', 'forks', 'revisions', 'proposals', 'comments']); } }