From 5ffa71dacd0c5d7b18012f807998a8e7b81397f0 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 17 Feb 2020 00:00:33 -0700 Subject: [PATCH] Update StoryController, fixes #2018 --- app/Http/Controllers/StoryController.php | 27 ++++++++++++++++-------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/StoryController.php b/app/Http/Controllers/StoryController.php index a7cfb971..68d93272 100644 --- a/app/Http/Controllers/StoryController.php +++ b/app/Http/Controllers/StoryController.php @@ -108,16 +108,25 @@ class StoryController extends Controller $profile = $request->user()->profile; $following = $profile->following->pluck('id')->toArray(); - $groupBy = config('database.default') == 'pgsql' ? 'id' : 'profile_id'; - $stories = Story::with('profile') - ->groupBy($groupBy) - ->whereIn('profile_id', $following) - ->where('expires_at', '>', now()) - ->orderByDesc('expires_at') - ->take(9) - ->get() - ->map(function($s, $k) { + if(config('database.default') == 'pgsql') { + $db = Story::with('profile') + ->whereIn('profile_id', $following) + ->where('expires_at', '>', now()) + ->distinct('profile_id') + ->take(9) + ->get(); + } else { + $db = Story::with('profile') + ->whereIn('profile_id', $following) + ->where('expires_at', '>', now()) + ->orderByDesc('expires_at') + ->groupBy('profile_id') + ->take(9) + ->get(); + } + + $stories = $db->map(function($s, $k) { return [ 'id' => (string) $s->id, 'photo' => $s->profile->avatarUrl(),