42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Advert;
|
|
use App\Models\Category;
|
|
|
|
class CategoryController extends Controller
|
|
{
|
|
|
|
/**
|
|
* 显示分类
|
|
* @param Category $category [description]
|
|
* @return [type] [description]
|
|
*/
|
|
public function index(Category $category)
|
|
{
|
|
if ($category->type == Category::TYPE_SHOW && $category->article_id) {
|
|
return redirect("articles/" . $category->article_id);
|
|
} else {
|
|
$template = 'show';
|
|
if ($category->template) {
|
|
$template = $category->template;
|
|
}
|
|
$articles = $category->relations(Category::TYPE_ARTICLE)
|
|
->where('status', 1)
|
|
->latest()
|
|
->paginate(8);
|
|
|
|
$parent = $category;
|
|
if ($category->childrens->isEmpty() && $category->parent) {
|
|
$parent = $category->parent;
|
|
}
|
|
|
|
$advert = Advert::where('category_id', 73)->first();
|
|
|
|
return view('category.' . $template, compact('articles', 'category', 'parent', 'advert'));
|
|
}
|
|
}
|
|
|
|
}
|