调整分类

This commit is contained in:
2021-04-01 17:03:48 +08:00
parent 782fa9e088
commit 507811b713
11 changed files with 181 additions and 66 deletions

View File

@@ -16,17 +16,15 @@ class ArticleController extends Controller
*/
public function show(Article $article)
{
$parent = $category = $article->category;
if ($category->id) {
$parent = getTopCate($category->id);
}
$categories = $article->categories;
$next = Article::where('id', '>', $article->id)
->whereHas('categories', function ($q) use ($categories) {
$q->whereIN('id', $categories->pluck('id'));
})
->where('status', 1)
->first();
$next = Article::where('id', '>', $article->id)
->where('category_id', $article->category_id)
->where('status', 1)
->first();
return view('article.show', compact('article', 'next', 'parent', 'category'));
return view('article.show', compact('article', 'next'));
}
@@ -38,7 +36,6 @@ class ArticleController extends Controller
->when($title, function ($q) use ($title) {
$q->where('title', 'like', "%{$title}%");
})
->where('category_id', '>', 0)
->paginate();
return view('article.search', compact('articles'));

View File

@@ -16,26 +16,17 @@ class IndexController extends Controller
*/
public function index()
{
$fydt = $this->getArticle([6], 9); //分院动态
$kydt = $this->getArticle([9], 9); //科研动态
$ldbz = $this->getArticle([3], 4); //领导班子
$kycg = $this->getArticle([10], 8); //科研成果
$rctd = $this->getArticle([4], 9); //人才团队介绍
$info = Article::where('category_id', 2)->first(); //院所介绍
$links = Link::get();
$advert = Advert::where('category_id', 26)->latest('sort')->first();
$center_advert = Advert::where('category_id', 28)->latest('sort')->first();
return view('index.index', compact('advert', 'center_advert', 'fydt', 'kydt', 'ldbz', 'kycg', 'rctd', 'info'));
return view('index.index');
}
//通用获取文章
public function getArticle($category_ids, $take = 3)
{
return Article::whereIn('category_id', $category_ids)
return Article::latest('sort')
->whereHas('categories', function ($q) use ($category_ids) {
$q->where('id', $category_ids);
})
->select('id', 'description', 'title', 'created_at', 'cover', 'content')
->latest('sort')
->latest()
->take($take)
->get();