flash('danger', 'Strona nie znaleziona.'); $this->redirect('/sites'); return; } $topics = Topic::findBySiteWithGlobal((int) $id); $globalTopics = GlobalTopic::findAllGrouped(); $this->view('topics/index', ['site' => $site, 'topics' => $topics, 'globalTopics' => $globalTopics]); } public function store(string $id): void { Auth::requireLogin(); $validator = new Validator(); $validator->required('name', $this->input('name'), 'Nazwa tematu'); if (!$validator->isValid()) { $this->flash('danger', $validator->getFirstError()); $this->redirect("/sites/{$id}/topics"); return; } Topic::create([ 'site_id' => (int) $id, 'global_topic_id' => $this->input('global_topic_id') ? (int) $this->input('global_topic_id') : null, 'name' => $this->input('name'), 'description' => $this->input('description', ''), 'wp_category_id' => $this->input('wp_category_id') ? (int) $this->input('wp_category_id') : null, 'is_active' => $this->input('is_active') ? 1 : 0, ]); $this->flash('success', 'Temat został dodany.'); $this->redirect("/sites/{$id}/topics"); } public function update(string $id): void { Auth::requireLogin(); $topic = Topic::find((int) $id); if (!$topic) { $this->flash('danger', 'Temat nie znaleziony.'); $this->redirect('/sites'); return; } Topic::update((int) $id, [ 'global_topic_id' => $this->input('global_topic_id') ? (int) $this->input('global_topic_id') : null, 'name' => $this->input('name'), 'description' => $this->input('description', ''), 'wp_category_id' => $this->input('wp_category_id') ? (int) $this->input('wp_category_id') : null, 'is_active' => $this->input('is_active') ? 1 : 0, ]); $this->flash('success', 'Temat został zaktualizowany.'); $this->redirect("/sites/{$topic['site_id']}/topics"); } public function destroy(string $id): void { Auth::requireLogin(); $topic = Topic::find((int) $id); if (!$topic) { $this->flash('danger', 'Temat nie znaleziony.'); $this->redirect('/sites'); return; } $siteId = $topic['site_id']; Topic::delete((int) $id); $this->flash('success', 'Temat został usunięty.'); $this->redirect("/sites/{$siteId}/topics"); } }