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 @@
There are no topics at the moment!
+ Create the first topic +