39 lines
1.0 KiB
PHP
39 lines
1.0 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 route('article.show', $category->relations);
|
|
}
|
|
}
|
|
$parent = getTopCate($category->id);
|
|
|
|
$template = array_flip(config('haai.category'));
|
|
if (isset($template[$category->id])) {
|
|
return view('category.' . $template[$category->id], compact('category', 'parent'));
|
|
}
|
|
|
|
return redirect(route('category.list', $category));
|
|
|
|
}
|
|
|
|
//显示文章列表
|
|
public function list(Category $category)
|
|
{
|
|
$articles = Article::where('category_id', $category->id)->where('status', 1)->paginate();
|
|
$parent = getTopCate($category->id);
|
|
|
|
return view('category.list', compact('category', 'parent', 'articles'));
|
|
}
|
|
|
|
} |