67 lines
1.8 KiB
PHP
67 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Article;
|
|
use App\Models\Category;
|
|
|
|
class CategoryController extends Controller
|
|
{
|
|
|
|
//显示分类
|
|
public function show(Category $category)
|
|
{
|
|
if ($category->type == Category::TYPE_SHOW) {
|
|
if ($category->relations) {
|
|
return redirect(route('article.show', $category->relations));
|
|
}
|
|
}
|
|
$parent = getTopCate($category->id);
|
|
|
|
$template = array_flip(config('haai.category'));
|
|
if (isset($template[$category->id]) && ! in_array($category->id, config('haai.no_list'))) {
|
|
return view('category.'.$template[$category->id], compact('category', 'parent'));
|
|
}
|
|
|
|
return redirect(route('category.list', $category));
|
|
|
|
}
|
|
|
|
//显示文章列表
|
|
public function list(Category $category)
|
|
{
|
|
$take = 15;
|
|
$template = 'category.list';
|
|
|
|
if (in_array($category->id, [29, 30])) {
|
|
$take = 16;
|
|
$template = 'category.persons';
|
|
}
|
|
|
|
$cate_ids = Category::where('parent_id', $category->id)
|
|
->orWhere('id', $category->id)
|
|
->where('status', 1)
|
|
->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_SHOW])
|
|
->pluck('id')
|
|
->toArray();
|
|
|
|
$articles = Article::where('status', 1)
|
|
->ByCategory($cate_ids)
|
|
->latest('sort')
|
|
->latest()
|
|
->paginate($take);
|
|
|
|
$parent = getTopCate($category->id);
|
|
|
|
if (in_array($category->id, [55, 54]) && $category->children->isEmpty()) {
|
|
$parent = $category->parent;
|
|
}
|
|
|
|
if ($category->children->isEmpty()) {
|
|
$parent = $category->parent;
|
|
}
|
|
|
|
return view($template, compact('category', 'parent', 'articles'));
|
|
}
|
|
|
|
} |