Beispiel #1
0
    }
    $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) {
                $notice = $reply->notifications()->create(['body' => $app->auth->getFullNameOrUsername() . ' has replied to your thread.', 'user_id' => $app->auth->id, 'notify_user_id' => $thread->author_id]);
                $reply->notifications()->save($notice);
            }
            $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');
$app->get('/forum/reply/delete/:id', $modOrAdmin(), function ($id) use($app) {
    $reply = ForumComment::find($id);