first
This commit is contained in:
34
app/Http/Controllers/CategoryController.php
Normal file
34
app/Http/Controllers/CategoryController.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?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 {
|
||||
$articles = $category->relations(Category::TYPE_ARTICLE)->paginate(8);
|
||||
$parent = $category;
|
||||
|
||||
if ($category->childrens->isEmpty() && $category->parent) {
|
||||
$parent = $category->parent;
|
||||
}
|
||||
|
||||
$advert = Advert::where('category_id', 73)->first();
|
||||
|
||||
return view('category.show', compact('articles', 'category', 'parent', 'advert'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user