34 lines
759 B
PHP
34 lines
759 B
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));
|
|
}
|
|
|
|
return redirect('/');
|
|
}
|
|
|
|
$articles = Article::where('category_id', $category->id)
|
|
->latest('sort')
|
|
->latest()
|
|
->paginate();
|
|
|
|
$parent = $category->getTop();
|
|
|
|
return view('category.show', compact('category', 'parent', 'articles'));
|
|
|
|
}
|
|
|
|
}
|