if ($thread == null) { $app->flash('error', 'That thread could not be found.'); return $app->response->redirect($app->urlFor('forum.home')); } $request = $app->request; $body = $request->post('body'); $v = $app->validation; $v->validate(['body' => [$body, 'required|min(3)|max(65000)']]); if ($v->passes()) { $reply = new ForumComment(); $reply->body = $body; $reply->group_id = $thread->group_id; $reply->category_id = $thread->category_id; $reply->thread_id = $thread->id; $reply->author_id = $app->auth->id; if ($reply->save()) { $threadAuthor = $app->user->where('id', $thread->author_id)->first(); if ($threadAuthor) { $threadAuthor->notifications()->create(['body' => $app->auth->getFullNameOrUsername() . ' has replied to your thread.', 'user_id' => $app->auth->id]); } $app->flash('success', 'Your reply has been posted.'); return $app->response->redirect($app->urlFor('forum.thread', ['id' => $thread->id])); } else { $app->flash('error', 'There was an error posting your reply.'); return $app->response->redirect($app->urlFor('forum.thread', ['id' => $thread->id])); } } $category = $thread->category; $replies = $thread->comments()->get()->load('author'); $app->render('forum/thread.php', ['thread' => $thread->load('latestComment', 'author'), 'category' => $category, 'request' => $request, 'errors' => $v->errors(), 'threadmodal' => '#thread_form_modal', 'replies' => $replies]); })->name('forum.reply.create.post');