@@ -15,14 +15,32 @@ class PostController extends Controller
1515{
1616 public $ action = "append " ;
1717
18+ /**
19+ * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Foundation\Application|null
20+ */
21+ public function feed ()
22+ {
23+ $ popular = Post::withCount ('likers ' )
24+ ->withCount ('comments ' )
25+ ->orderBy ('likers_count ' , 'desc ' )
26+ ->orderBy ('created_at ' , 'desc ' )
27+ ->cursorPaginate (5 );
28+
29+ return view ('post.list ' , [
30+ 'popular ' => $ popular ,
31+ ]);
32+ }
33+
1834 /**
1935 * @param \App\Models\Post $post
2036 *
2137 * @return \Illuminate\Contracts\View\View
2238 */
2339 public function show (Post $ post )
2440 {
25- $ post ->with ('comments ' );
41+ $ post ->load (['comments ' , 'author ' ])
42+ ->loadCount ('comments ' )
43+ ->loadCount ('likers ' );
2644
2745 return view ('post.show ' , [
2846 'post ' => $ post ,
@@ -103,12 +121,15 @@ public function delete(Request $request, Post $post)
103121 */
104122 public function list (Request $ request )
105123 {
106- $ posts = Post::with (['user ' ])
124+ $ posts = Post::with (['author ' ])
107125 ->withCount ('comments ' )
126+ ->withCount ('likers ' )
108127 ->when ($ request ->has ('user_id ' ), fn (Builder $ query ) => $ query ->where ('user_id ' , $ request ->get ('user_id ' )))
109128 ->orderBy ('id ' , 'desc ' )
110129 ->cursorPaginate (3 );
111130
131+ $ posts = $ request ->user ()->attachLikeStatus ($ posts );
132+
112133 return view ('particles.posts.list ' , [
113134 'posts ' => $ posts ,
114135 'isMyProfile ' => $ request ->has ('user_id ' ) && $ request ->user ()?->id == $ request ->get ('user_id ' ),
0 commit comments