$v = $app->validation; $v->validate(['name' => [$name, 'required|min(5)|uniqueForumGroup']]); if ($v->passes()) { $group = new ForumGroup(); $group->title = $name; $group->author_id = $app->auth->id; if ($group->save()) { $app->flash('success', 'Forum group created successfully.'); return $app->response->redirect($app->urlFor('forum.home')); } else { $app->flash('error', 'There was an error creating the forum group.'); return $app->response->redirect($app->urlFor('forum.home')); } } $groups = ForumGroup::all(); $categories = ForumCategory::all(); $app->render('forum/index.php', ['groups' => $groups, 'categories' => $categories, 'request' => $request, 'errors' => $v->errors(), 'modal' => '#group_form_modal']); })->name('forum.group.create'); $app->get('/forum/group/delete/:id', $admin(), function ($id) use($app) { $group = ForumGroup::find($id); if (!$group) { $app->flash('global', 'Unable to delete, group not found.'); return $app->response->redirect($app->urlFor('forum.home')); } else { $delCategories = $group->categories(); $delThreads = $group->threads(); $delComments = $group->comments(); $delCa = true; $delCo = true; $delT = true; if ($delCategories->count() > 0) {
$thread->body = $body; $thread->group_id = $category->group_id; $thread->category_id = $categoryID; $thread->author_id = $app->auth->id; if ($thread->save()) { $app->flash('success', 'Your thread has been created.'); return $app->response->redirect($app->urlFor('forum.thread', ['id' => $thread->id])); } else { $app->flash('error', 'Your thread could not be created.'); return $app->response->redirect($app->urlFor('forum.category', ['id' => $categoryID])); } } $app->render('forum/newthread.php', ['category' => $category, 'request' => $request, 'errors' => $v->errors()]); })->name('forum.thread.create.post'); $app->get('/forum/:id/thread/new', $authenticated(), function ($id) use($app) { $category = ForumCategory::find($id); if ($category == null) { $app->flash('error', 'Category was not found'); return $app->response->redirect($app->urlFor('forum.home')); } $app->render('forum/newthread.php', ['category' => $category]); })->name('forum.thread.create'); $app->get('/forum/thread/delete/:id', $modOrAdmin(), function ($id) use($app) { $thread = ForumThread::find($id); if (!$thread) { $app->flash('global', 'Unable to delete, thread not found.'); return $app->response->redirect($app->urlFor('forum.home')); } else { $delComments = $thread->comments(); $delCo = true; if ($delComments->count() > 0) {
public function validate_uniqueForumCategory($value, $input, $args) { return !(bool) ForumCategory::where('title', $value)->count(); }
if ($v->passes()) { $category = new ForumCategory(); $category->title = $name; $category->description = $description; $category->author_id = $app->auth->id; if ($groupID != null) { $category->group_id = $groupID; } if ($categoryID) { $tempCat = ForumCategory::find($categoryID); $category->group_id = $tempCat->group_id; } if ($category->save()) { $app->flash('success', 'Forum category created successfully.'); return $app->response->redirect($app->urlFor('forum.home')); } else { $app->flash('error', 'There was an error creating the forum category.'); return $app->response->redirect($app->urlFor('forum.home')); } } if ($groupID) { $groups = ForumGroup::all(); $categories = ForumCategory::all(); $app->render('forum/index.php', ['groups' => $groups, 'categories' => $categories, 'request' => $request, 'errors' => $v->errors(), 'categorymodal' => '#category_form_modal']); } if ($categoryID) { $category = ForumCategory::find($categoryID); $threads = $category->threads()->get()->load('author'); $app->render('forum/category.php', ['category' => $category, 'threads' => $threads, 'categorymodal' => '#category_form_modal', 'request' => $request, 'errors' => $v->errors()]); } })->name('forum.category.create');