add Longest and Shortest filters

master
Ondřej Hruška 6 years ago
parent 3629c977e5
commit 57a8fc58d6
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 12
      app/Http/Controllers/DashController.php
  2. 3
      app/Models/Table.php

@ -30,6 +30,8 @@ class DashController extends Controller
// 'most-liked' => 'Most Liked', // 'most-liked' => 'Most Liked',
'newest' => 'Newest', 'newest' => 'Newest',
'oldest' => 'Oldest', 'oldest' => 'Oldest',
'most-rows' => 'Longest',
'least-rows' => 'Shortest',
]; ];
$data['users'] = User::orderBy('updated_at', 'desc') $data['users'] = User::orderBy('updated_at', 'desc')
@ -54,6 +56,16 @@ class DashController extends Controller
case 'most-liked': case 'most-liked':
$tableQuery = $tableQuery->orderBy('favourites_count', 'desc'); $tableQuery = $tableQuery->orderBy('favourites_count', 'desc');
break; 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': case 'newest':
$tableQuery = $tableQuery->orderBy('created_at', 'desc'); $tableQuery = $tableQuery->orderBy('created_at', 'desc');
break; break;

@ -188,7 +188,8 @@ class Table extends BaseModel
public function scopeForList(Builder $query) 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']); ->withCount(['favourites', 'forks', 'revisions', 'proposals', 'comments']);
} }
} }

Loading…
Cancel
Save