diff --git a/app/Http/Controllers/Forum/ThreadsController.php b/app/Http/Controllers/Forum/ThreadsController.php index 04de65f..ef14d51 100644 --- a/app/Http/Controllers/Forum/ThreadsController.php +++ b/app/Http/Controllers/Forum/ThreadsController.php @@ -15,7 +15,12 @@ class ThreadsController extends Controller $category = Category::where('slug', $categorySlug)->first(); $thread = Thread::where('slug', $threadSlug)->first(); - $topics = Topic::where('category_id', $category->id) + if (!$category || !$thread) { + abort(404); + } + + $topics = Topic::with('author') + ->where('category_id', $category->id) ->where('thread_id', $thread->id) ->paginate(15); diff --git a/app/Http/Controllers/Forum/TopicsController.php b/app/Http/Controllers/Forum/TopicsController.php index 316a576..cfa79aa 100644 --- a/app/Http/Controllers/Forum/TopicsController.php +++ b/app/Http/Controllers/Forum/TopicsController.php @@ -16,14 +16,24 @@ class TopicsController extends Controller public function show(string $categorySlug, string $threadSlug, string $topicSlug) { $thread = Thread::with('category')->where('slug', $threadSlug)->first(); - $topic = Topic::where('slug', $topicSlug)->first(); + $topic = Topic::with('author')->where('slug', $topicSlug)->first(); + + if (!$topic || !$thread) { + abort(404); + } $topic->views_no = $topic->views_no+1; $topic->save(); $posts = Post::with('author')->where('topic_id', $topic->id)->paginate(15); - return view('forum.topics.show', compact('thread', 'topic', 'posts')); + // Get similar topics from the same thread + $similarTopics = Topic::where('thread_id', $thread->id) + ->where('id', '!=', $topic->id) + ->limit(5) + ->get(); + + return view('forum.topics.show', compact('thread', 'topic', 'posts', 'similarTopics')); } public function create(string $categorySlug, string $threadSlug) diff --git a/app/Models/Forum/Topic.php b/app/Models/Forum/Topic.php index e284b64..934b568 100644 --- a/app/Models/Forum/Topic.php +++ b/app/Models/Forum/Topic.php @@ -21,4 +21,9 @@ class Topic extends Model 'views_no', 'replies_no', ]; + + public function author() + { + return $this->belongsTo(\App\Models\User::class, 'user_id'); + } } diff --git a/resources/js/app.js b/resources/js/app.js index c690f88..acb66fa 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -53,7 +53,7 @@ $(".my-rating").starRating({ } }); -$('.mark-as-seen-btn').on('click', function (e) { +$('.mark-action').on('click', function (e) { e.preventDefault(); let url = '/lists/' + $(this).data('list') + '/' + $(this).data('id') + '/' + $(this).data('type'); var self = this @@ -72,7 +72,7 @@ $('.mark-as-seen-btn').on('click', function (e) { return false; }); -$('.like-btn').on('click', function (e) { +$('.like-action').on('click', function (e) { e.preventDefault(); let url = '/lists/' + $(this).data('list') + '/' + $(this).data('id') + '/' + $(this).data('type'); var self = this diff --git a/resources/views/forum/thread.blade.php b/resources/views/forum/thread.blade.php index 4574a3a..ea35b12 100644 --- a/resources/views/forum/thread.blade.php +++ b/resources/views/forum/thread.blade.php @@ -4,85 +4,111 @@
-
-
-
-

{{ $thread->name }}

-
- -
-
-
- {{ $thread->description }} -
-
-
-
- @if($topics->count()) -
+
+
+

-
- -
-
- Topic Name / Author -
-
- Views +
+ {{ $thread->name }}
- Last post + + New topic +
+

+
+
+ {{ $thread->description }} +
- @foreach($topics as $topic) -
+
+
+ @if($topics->count()) +
- +
- {{ $topic->name }}
- Creator + Topic Name / Author
- {{ $topic->views_no }} - {{ $topic->replies_no }} + Stats
- last + Last post
- @endforeach - @else -
- There are no topics at the moment! Go ahead, post the first one! -
- @endif + @foreach($topics as $topic) +
+
+
+ +
+
+ {{ $topic->name }}
+ Created by {{ $topic->author->name ?? 'Unknown User' }} {{ $topic->created_at ? $topic->created_at->diffForHumans() : 'N/A' }} +
+
+ {{ $topic->views_no }}
+ {{ $topic->replies_no }} +
+
+ {{ $topic->updated_at ? $topic->updated_at->diffForHumans() : 'N/A' }} +
+
+
+ @if(!$loop->last) +
+ @endif + @endforeach + @else +
+

There are no topics at the moment!

+ Create the first topic +
+ @endif +
+ {{ $topics->links() }}
- +
+
+
Thread Stats
+
+
+
    +
  • + + Topics: {{ $topics->total() }} +
  • +
  • + + Created: {{ $thread->created_at ? $thread->created_at->diffForHumans() : 'N/A' }}
-
- rate -
diff --git a/resources/views/forum/topics/show.blade.php b/resources/views/forum/topics/show.blade.php index 1b3ced7..6e02a6b 100644 --- a/resources/views/forum/topics/show.blade.php +++ b/resources/views/forum/topics/show.blade.php @@ -10,7 +10,7 @@
{{ $topic->name }}
- Created by {{ $topic->author->name }} | {{ $topic->created_at->diffForHumans() }} + Created by {{ $topic->author->name ?? 'Unknown User' }} | {{ $topic->created_at ? $topic->created_at->diffForHumans() : 'N/A' }}
@@ -20,13 +20,17 @@
- {{ $post->author->name }}author->name ?? 'Unknown User'; + $avatarUrl = $post->author->avatar ?? 'https://ui-avatars.com/api/?name=' . urlencode($authorName); + @endphp + {{ $authorName }}
- {{ $post->author->name }} + {{ $authorName }}
@@ -35,7 +39,7 @@ {!! $post->content !!}