@@ -38,11 +38,11 @@ public function index(Request $request)
3838 }
3939
4040 return $ subjectsQuery ->orderBy ('sort_order ' , 'asc ' )
41- ->with (['nodes ' => function ($ q ) {
42- $ q ->select ('id ' , 'subject_id ' , 'name ' , ' slug ' )
41+ ->with (['chapters ' => function ($ q ) {
42+ $ q ->select ('id ' , 'subject_id ' , 'name ' )
4343 ->orderBy ('sort_order ' );
4444 }])
45- ->get (['id ' , 'name ' , 'slug ' , ' course ' , 'group ' ])
45+ ->get (['id ' , 'name ' , 'course ' , 'group ' ])
4646 ->toArray ();
4747 });
4848
@@ -102,19 +102,27 @@ private function getFeed(string $course, string $group, string $sort, int $page
102102 });
103103 })
104104 ->when ($ currentUserId , fn ($ q ) => $ q ->where ('user_id ' , '!= ' , $ currentUserId ))
105- ->with (['user:id,name,username,image_path,institution,is_verified ' , 'subject:id,name,slug, group ' , 'node :id,name,slug ' ])
105+ ->with (['user:id,name,username,image_path,institution,is_verified ' , 'subject:id,name,group ' , 'chapter :id,name ' ])
106106 ->withCount ('answers ' );
107107
108108 // 2. Resources (4 items)
109109 $ resourcesQuery = Resource ::approved ()
110- ->whereHas ('node.subject ' , function ($ s ) use ($ course , $ group ) {
111- $ s ->where ('course ' , $ course );
112- if ($ group ) {
113- $ s ->whereIn ('group ' , [$ group , 'common ' ]);
114- }
110+ ->where (function ($ query ) use ($ course , $ group ) {
111+ $ query ->whereHas ('subject ' , function ($ s ) use ($ course , $ group ) {
112+ $ s ->where ('course ' , $ course );
113+ if ($ group ) {
114+ $ s ->whereIn ('group ' , [$ group , 'common ' ]);
115+ }
116+ })->orWhereHas ('chapter.subject ' , function ($ s ) use ($ course , $ group ) {
117+ $ s ->where ('course ' , $ course );
118+ if ($ group ) {
119+ $ s ->whereIn ('group ' , [$ group , 'common ' ]);
120+ }
121+ });
115122 })
116123 ->when ($ currentUserId , fn ($ q ) => $ q ->where ('user_id ' , '!= ' , $ currentUserId ))
117- ->with (['user:id,name,username,image_path,institution,is_verified ' , 'node:id,name,slug,subject_id ' , 'node.subject:id,name,course,slug,group ' ]);
124+ ->with (['user:id,name,username,image_path,institution,is_verified ' , 'chapter:id,name,subject_id ' , 'chapter.subject:id,name,course,group ' , 'subject:id,name,course,group ' ])
125+ ->withCount ('comments ' );
118126
119127 // 3. Blogs (2 items)
120128 $ blogsQuery = Blog ::where ('is_published ' , true )
0 commit comments