소스 검색

Update StoryController, fixes #2018

Daniel Supernault 5 년 전
부모
커밋
5ffa71dacd
1개의 변경된 파일18개의 추가작업 그리고 9개의 파일을 삭제
  1. 18 9
      app/Http/Controllers/StoryController.php

+ 18 - 9
app/Http/Controllers/StoryController.php

@@ -108,16 +108,25 @@ class StoryController extends Controller
 
 
 		$profile = $request->user()->profile;
 		$profile = $request->user()->profile;
 		$following = $profile->following->pluck('id')->toArray();
 		$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 [
 			return [
 				'id' => (string) $s->id,
 				'id' => (string) $s->id,
 				'photo' => $s->profile->avatarUrl(),
 				'photo' => $s->profile->avatarUrl(),