Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/Http/Controllers/ForumController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public function index(Request $request): Response
->when(! ($myPosts && auth()->check()), fn ($q) => $q->approved())
->with([
'user:id,name,username,image_path,institution,is_verified',
'subject:id,name,course,slug',
'node:id,name,slug',
'subject:id,name,course',
'chapter:id,name',
])
->filter($filters);

Expand Down
28 changes: 18 additions & 10 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public function index(Request $request)
}

return $subjectsQuery->orderBy('sort_order', 'asc')
->with(['nodes' => function ($q) {
$q->select('id', 'subject_id', 'name', 'slug')
->with(['chapters' => function ($q) {
$q->select('id', 'subject_id', 'name')
->orderBy('sort_order');
}])
->get(['id', 'name', 'slug', 'course', 'group'])
->get(['id', 'name', 'course', 'group'])
->toArray();
});

Expand Down Expand Up @@ -102,19 +102,27 @@ private function getFeed(string $course, string $group, string $sort, int $page
});
})
->when($currentUserId, fn ($q) => $q->where('user_id', '!=', $currentUserId))
->with(['user:id,name,username,image_path,institution,is_verified', 'subject:id,name,slug,group', 'node:id,name,slug'])
->with(['user:id,name,username,image_path,institution,is_verified', 'subject:id,name,group', 'chapter:id,name'])
->withCount('answers');

// 2. Resources (4 items)
$resourcesQuery = Resource::approved()
->whereHas('node.subject', function ($s) use ($course, $group) {
$s->where('course', $course);
if ($group) {
$s->whereIn('group', [$group, 'common']);
}
->where(function ($query) use ($course, $group) {
$query->whereHas('subject', function ($s) use ($course, $group) {
$s->where('course', $course);
if ($group) {
$s->whereIn('group', [$group, 'common']);
}
})->orWhereHas('chapter.subject', function ($s) use ($course, $group) {
$s->where('course', $course);
if ($group) {
$s->whereIn('group', [$group, 'common']);
}
});
})
->when($currentUserId, fn ($q) => $q->where('user_id', '!=', $currentUserId))
->with(['user:id,name,username,image_path,institution,is_verified', 'node:id,name,slug,subject_id', 'node.subject:id,name,course,slug,group']);
->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'])
->withCount('comments');

// 3. Blogs (2 items)
$blogsQuery = Blog::where('is_published', true)
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/NoteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function index(Request $request): Response
$query->where('chapter_id', (int) $chapterId);
}

if (in_array($type, ['note', 'video', 'practical', 'other'], true)) {
if (in_array($type, ['note', 'lecture_sheet', 'marked_book', 'video', 'practical', 'other'], true)) {
$query->where('resource_type', $type);
}

Expand Down
12 changes: 6 additions & 6 deletions app/Http/Controllers/ResourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ public function show($id)
// Fallback for non-approved (pending / rejected) viewing by owner or moderator
$resource = Resource::with([
'user:id,name,username,image_path',
'node:id,name,slug,subject_id',
'node.subject:id,name,slug,course',
'subject:id,name,slug,course',
'chapter:id,name,subject_id',
'chapter.subject:id,name,course',
'subject:id,name,course',
])->findOrFail($id);

if (! $resource->relationLoaded('subject') || ! $resource->subject) {
$resource->setRelation('subject', $resource->node?->subject);
$resource->setRelation('subject', $resource->chapter?->subject);
}

$isOwner = $user && $user->id === $resource->user_id;
Expand All @@ -99,8 +99,8 @@ public function show($id)
$subjects = ($isModerator || $isOwner)
? Subject::where('is_disabled', false)
->orderBy('sort_order')
->with(['nodes' => fn ($q) => $q->select('id', 'subject_id', 'name', 'slug')->orderBy('sort_order')])
->get(['id', 'name', 'slug', 'course', 'group'])
->with(['chapters' => fn ($q) => $q->select('id', 'subject_id', 'name')->orderBy('sort_order')])
->get(['id', 'name', 'course', 'group'])
: [];

$comments = ResourceComment::where('resource_id', $id)
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/UserProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function show(string $username)

$forumPosts = ForumPost::where('user_id', $user->id)
->approved()
->with(['subject:id,name,course,slug', 'node:id,name,slug'])
->with(['subject:id,name,course', 'chapter:id,name'])
->latest()
->take(5)
->get();
Expand All @@ -169,7 +169,7 @@ public function show(string $username)

$notes = Resource::where('user_id', $user->id)
->when(! $isOwner, fn ($q) => $q->where('status', 'approved'))
->with(['node:id,name,slug,subject_id', 'node.subject:id,name,course,slug', 'subject:id,name,course,slug'])
->with(['chapter:id,name,subject_id', 'chapter.subject:id,name,course', 'subject:id,name,course'])
->latest('id')
->take(5)
->get();
Expand Down
15 changes: 14 additions & 1 deletion resources/js/components/resources/ResourceFeedCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
FileText,
FlaskConical,
Loader2,
MessageSquare,
Play,
Share2,
Video,
Expand Down Expand Up @@ -61,6 +62,7 @@ interface Resource {
vote_score: number;
upvotes_count?: number;
downvotes_count?: number;
comments_count?: number;
created_at: string;
user?: User;
node?: NodeItem | null;
Expand Down Expand Up @@ -443,7 +445,7 @@ const shareResource = async () => {
<template v-if="resource.node?.subject">
<span class="text-slate-300 dark:text-gray-600">•</span>
<Link
:href="`/${resource.node.subject.slug}`"
:href="`/notes?subject=${resource.node.subject.id}`"
@click.stop
class="shrink-0 transition hover:text-indigo-600 dark:hover:text-indigo-400"
>
Expand Down Expand Up @@ -545,6 +547,17 @@ const shareResource = async () => {
direction="horizontal"
size="sm"
/>

<!-- Comment Count Button (Exactly matching Forum & Blog) -->
<Link
:href="`/resources/${resource.id}#comments`"
class="inline-flex items-center gap-1.5 rounded-xl border border-slate-200/80 bg-slate-50/70 px-2.5 py-1 text-xs font-semibold text-slate-700 transition hover:border-slate-300 hover:bg-slate-100 dark:border-gray-800 dark:bg-gray-800/60 dark:text-gray-300 dark:hover:bg-gray-800"
>
<MessageSquare
class="h-3.5 w-3.5 text-purple-600 dark:text-purple-400"
/>
<span>{{ resource.comments_count ?? 0 }} comments</span>
</Link>
</div>

<!-- Right: Clean Share Button (Exactly matching Forum & Blog) -->
Expand Down
Loading