view('admin/cases', [ 'cases' => (new CustomerCase())->all(), 'seg' => $this->seg(), ]); } public function create() { return $this->view('admin/cases_form', ['c' => null]); } public function store() { if (!csrf_check()) { $this->redirect('admin/cases'); } $cover = $this->uploadFile('cover') ?? $this->post('cover_url', ''); $model = new CustomerCase(); $id = $model->insert([ 'title' => $this->post('title'), 'slug' => '', 'customer' => $this->post('customer', ''), 'industry' => $this->post('industry', ''), 'cover' => $cover, 'summary' => $this->post('summary'), 'content' => $this->post('content'), 'published_at' => $this->post('published_at', date('Y-m-d')), 'sort_order' => (int) $this->post('sort_order', 0), 'status' => $this->post('status', 1) ? 1 : 0, 'views' => 0, 'layout' => $this->post('layout', ''), ]); // URL 标识留空时按记录序号顺序生成(短、稳定),避免中文标题导致过长 $slug = $this->post('slug') ? slugify($this->post('slug')) : (string)$id; $model->update($id, ['slug' => $slug]); $this->redirect('admin/cases'); } public function edit($id) { $case = (new CustomerCase())->find($id); if (!$case) { $this->redirect('admin/cases'); } return $this->view('admin/cases_form', ['c' => $case]); } public function update($id) { if (!csrf_check()) { $this->redirect('admin/cases'); } $model = new CustomerCase(); $case = $model->find($id); if (!$case) { $this->redirect('admin/cases'); } $cover = $this->uploadFile('cover'); if (!$cover && $this->post('cover_url')) $cover = $this->post('cover_url'); if (!$cover) $cover = $case['cover'] ?? ''; $model->update($id, [ 'title' => $this->post('title'), 'slug' => $this->post('slug') ? slugify($this->post('slug')) : (string)$id, 'customer' => $this->post('customer', ''), 'industry' => $this->post('industry', ''), 'cover' => $cover, 'summary' => $this->post('summary'), 'content' => $this->post('content'), 'published_at' => $this->post('published_at', date('Y-m-d')), 'sort_order' => (int) $this->post('sort_order', 0), 'status' => $this->post('status', 1) ? 1 : 0, 'layout' => $this->post('layout', ''), ]); $this->redirect('admin/cases'); } public function delete($id) { if (csrf_check()) { (new CustomerCase())->delete($id); } $this->redirect('admin/cases'); } }