render('guides_index', ['guides' => $this->guidesModel()->orderBy('published_at', 'DESC')->findAll()]); } public function create(): string { return $this->render('guides_form', ['guide' => null]); } public function store(): ResponseInterface { $post = $this->request->getPost(); $body = (string) ($post['body_md'] ?? ''); $this->guidesModel()->insert([ 'slug' => $post['slug'], 'title' => $post['title'], 'excerpt' => $post['excerpt'] ?? '', 'body_md' => $body, 'tool_slugs' => json_encode(array_filter(array_map('trim', explode(',', (string) ($post['tool_slugs'] ?? ''))))), 'seo_title' => $post['seo_title'] ?? null, 'seo_description' => $post['seo_description'] ?? null, 'reading_minutes' => max(1, (int) ceil(str_word_count(strip_tags($body)) / 220)), 'status' => $post['status'] === 'published' ? 'published' : 'draft', 'published_at' => date('Y-m-d H:i:s'), ]); service('cache')->clear(); return redirect()->to('/admin/guides'); } public function edit(int $id): string { return $this->render('guides_form', ['guide' => $this->guidesModel()->find($id)]); } public function update(int $id): ResponseInterface { $post = $this->request->getPost(); $body = (string) ($post['body_md'] ?? ''); $this->guidesModel()->update($id, [ 'title' => $post['title'], 'excerpt' => $post['excerpt'] ?? '', 'body_md' => $body, 'tool_slugs' => json_encode(array_filter(array_map('trim', explode(',', (string) ($post['tool_slugs'] ?? ''))))), 'seo_title' => $post['seo_title'] ?? null, 'seo_description' => $post['seo_description'] ?? null, 'reading_minutes' => max(1, (int) ceil(str_word_count(strip_tags($body)) / 220)), 'status' => $post['status'] === 'published' ? 'published' : 'draft', ]); service('cache')->clear(); return redirect()->to('/admin/guides'); } public function delete(int $id): ResponseInterface { $this->guidesModel()->delete($id); return redirect()->to('/admin/guides'); } }