diff --git a/app/Http/Controllers/RequestController.php b/app/Http/Controllers/RequestController.php
index a0bf103c89..14d53b6d9b 100644
--- a/app/Http/Controllers/RequestController.php
+++ b/app/Http/Controllers/RequestController.php
@@ -73,14 +73,17 @@ public function __construct(RequestFacetedRepository $faceted, ChatRepository $c
public function requests(Request $request)
{
$user = $request->user();
+
$requests = DB::table('requests')
->selectRaw('count(*) as total')
- ->selectRaw("count(case when filled_by != null then 1 end) as filled")
- ->selectRaw("count(case when filled_by = null then 1 end) as unfilled")
+ ->selectRaw('count(case when filled_by != null then 1 end) as filled')
+ ->selectRaw('count(case when filled_by = null then 1 end) as unfilled')
+ ->first();
+ $bounties = DB::table('requests')
+ ->selectRaw('coalesce(sum(bounty), 0) as total')
+ ->selectRaw('coalesce(sum(case when filled_by != null then 1 end), 0) as claimed')
+ ->selectRaw('coalesce(sum(case when filled_by = null then 1 end), 0) as unclaimed')
->first();
- $total_bounty = TorrentRequest::all()->sum('bounty');
- $claimed_bounty = TorrentRequest::whereNotNull('filled_by')->sum('bounty');
- $unclaimed_bounty = TorrentRequest::whereNull('filled_by')->sum('bounty');
$torrentRequests = TorrentRequest::with(['user', 'category', 'type'])->paginate(25);
$repository = $this->faceted;
@@ -90,9 +93,7 @@ public function requests(Request $request)
'repository' => $repository,
'user' => $user,
'requests' => $requests,
- 'total_bounty' => $total_bounty,
- 'claimed_bounty' => $claimed_bounty,
- 'unclaimed_bounty' => $unclaimed_bounty,
+ 'bounties' => $bounties,
]);
}
diff --git a/resources/views/requests/requests.blade.php b/resources/views/requests/requests.blade.php
index 252b75be4b..1e1cfb5183 100644
--- a/resources/views/requests/requests.blade.php
+++ b/resources/views/requests/requests.blade.php
@@ -190,9 +190,9 @@ class="form-horizontal form-condensed form-torrent-search form-bordered">
@lang('request.requests'): {{ $requests->total }} |
@lang('request.filled'): {{ $requests->filled }} |
@lang('request.unfilled'): {{ $requests->unfilled }} |
- @lang('request.total-bounty'): {{ $total_bounty }} @lang('bon.bon') |
- @lang('request.bounty-claimed'): {{ $claimed_bounty }} @lang('bon.bon') |
- @lang('request.bounty-unclaimed'): {{ $unclaimed_bounty }} @lang('bon.bon')
+ @lang('request.total-bounty'): {{ $bounties->total }} @lang('bon.bon') |
+ @lang('request.bounty-claimed'): {{ $bounties->claimed }} @lang('bon.bon') |
+ @lang('request.bounty-unclaimed'): {{ $bounties->unclaimed }} @lang('bon.bon')