Files
new_ine/app/Http/Controllers/CategoryController.php
2022-01-14 11:04:56 +08:00

68 lines
2.1 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Article;
use App\Models\Category;
class CategoryController extends Controller
{
/**
* 显示分类
*
* @param Category $category [description]
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View [type] [description]
*/
public function index(Category $category)
{
if ($category->type == Category::TYPE_SHOW && $category->article_id) {
return redirect("articles/".$category->article_id);
} elseif ($category->type == Category::TYPE_LINK && $category->url) {
return redirect()->away($category->url);
} else {
$template = 'show';
if ($category->template) {
$template = $category->template;
} else {
if ($category->type == Category::TYPE_VIDEO) {
$template = 'videos';
}
if ($category->type == Category::TYPE_ADVERT) {
$template = 'images';
}
if ($category->type == Category::TYPE_PHOTO) {
$template = 'photos';
}
}
//院所新闻
if ($category->id == 66) {
$articles = Article::ByCategory([66, 60, 61, 17, 26, 77])
->where('status', 1)
->latest('sort')
->latest('created_at')
->paginate();
} else {
$articles = $category->relations($category->type)
->where('status', 1)
->latest('sort')
->latest('created_at')
->paginate();
}
$parent = $category;
if ($category->childrens->isEmpty() && $category->parent) {
$parent = $category->parent;
}
return view('category.'.$template, compact('articles', 'category', 'parent'));
}
}
}