/** * @param $id * @return \Illuminate\Http\RedirectResponse */ public function destroy($id) { $article = Article::find($id); $article->delete(); ArticleRecommend::whereArticleId($id)->delete(); return $this->redirect->to('admin/article'); }
/** * @param $key * @param array $opinions * @return mixed */ public function position($key, $opinions = []) { $config = $this->config->get('page.recommends'); $config = array_merge($config[$key], $opinions); $articles = ArticleRecommend::wherePosition($key); if (isset($opinions['limit']) && $opinions['limit'] > 0) { $articles->take($config['limit']); } $articles = $articles->orderBy('created_at', 'desc')->get(); if (isset($config['thumbnail']) && is_array($config['thumbnail'])) { foreach ($articles as $k => $article) { $article = Article::find($article->article_id); if ($article) { preg_match_all("/<img([^>]*)\\s*src=('|\")([^'\"]+)('|\")/", $article->content, $matches); $hash = ''; $thumbnail = ''; if ($matches && $matches[3]) { $matches = array_unique($matches[3]); if ($matches[0] && $this->file->exists(public_path($matches[0]))) { $thumbnail = $matches[0]; $hash = hash_file('md5', public_path($matches[0]), false); } } if ($thumbnail && $hash) { $path = '/uploads/thumbnails/' . $config['thumbnail']['width'] . 'X' . $config['thumbnail']['height'] . '/' . $hash . '.' . $this->file->extension(public_path($thumbnail)); $directory = public_path('/uploads/thumbnails/' . $config['thumbnail']['width'] . 'X' . $config['thumbnail']['height'] . '/'); if (!$this->file->isDirectory($directory)) { $this->file->makeDirectory($directory, 0777, true, true); } if (!$this->file->exists(public_path($path))) { $image = Image::make($thumbnail, $config['thumbnail']); $image->save(public_path($path)); } $article->thumbnail = $path; } $articles->put($k, $article); } else { $articles->forget($k); } } } return $this->view->make($config['template'])->withArticles($articles); }