调整页面
This commit is contained in:
@@ -10,7 +10,7 @@ class CategoryController extends Controller
|
||||
|
||||
/**
|
||||
* 显示分类
|
||||
* @param Category $category [description]
|
||||
* @param Category $category [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function index(Category $category)
|
||||
@@ -18,15 +18,15 @@ class CategoryController extends Controller
|
||||
if ($category->type == Category::TYPE_SHOW && $category->article_id) {
|
||||
return redirect("articles/" . $category->article_id);
|
||||
} else {
|
||||
$articles = $category->relations(Category::TYPE_ARTICLE)->paginate();
|
||||
$articles = $category->relations(Category::TYPE_ARTICLE)->paginate(2);
|
||||
$parent = $category;
|
||||
if ($category->childrens->isEmpty()) {
|
||||
if ($parent->childrens->isEmpty()) {
|
||||
$parent = $category->parent;
|
||||
}
|
||||
|
||||
$advert = Advert::where('category_id',73)->first();
|
||||
$advert = Advert::where('category_id', 73)->first();
|
||||
|
||||
return view('category.show', compact('articles', 'category', 'parent','advert'));
|
||||
return view('category.show', compact('articles', 'category', 'parent'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,18 +19,19 @@ class Controller extends BaseController
|
||||
{
|
||||
//顶部分类
|
||||
$categorys = Category::where('status', 1)
|
||||
->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_SHOW])
|
||||
->where('top_show', 1)
|
||||
->orderBy('order', 'desc')
|
||||
->select('id', 'title')
|
||||
->get();
|
||||
->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_SHOW])
|
||||
->where('top_show', 1)
|
||||
->latest('order')
|
||||
->select('id', 'title')
|
||||
->get();
|
||||
|
||||
//地步友情链接
|
||||
if (url()->current() == route('index.index')){
|
||||
if (url()->current() == route('index.index')) {
|
||||
$adverts = Advert::where('category_id', 72)->get();
|
||||
}else{
|
||||
} else {
|
||||
$adverts = Advert::where('category_id', 73)->get();
|
||||
}
|
||||
|
||||
View::share('all_categorys', $categorys);
|
||||
View::share('adverts', $adverts);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Advert;
|
||||
use App\Models\Article;
|
||||
use App\Models\Category;
|
||||
use App\Models\Link;
|
||||
@@ -16,30 +17,23 @@ class IndexController extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$xwdt = $this->getArticle([53]); //新闻动态
|
||||
$kjpt = $this->getArticle([18]); //科技平台
|
||||
$zcjc = $this->getArticle([8]); //政府决策服务
|
||||
$zmzj = $this->getArticle([74, 127, 88]); //专家学者
|
||||
$tjgg = $this->getArticle([54]); //通知公告
|
||||
$kjlt = $this->getArticle([58]); //科技发展论坛
|
||||
$cxtd = $this->getArticle(Category::find(43)->getAllChildrenId(), 5); //创新团队
|
||||
$info = Article::where('category_id', 1)->first(); //简介
|
||||
|
||||
$kxyts = $this->getArticle(Category::find(17)->getAllChildrenId(), 10); //科学研究与特色品牌建设
|
||||
$yjzx = $this->getArticle([61], 2); //研究中心
|
||||
//研究中心
|
||||
$links = Link::get();
|
||||
|
||||
return view('index.index', compact('links', 'xwdt', 'kjpt', 'zcjc', 'zmzj', 'tjgg', 'kjlt', 'tjgg', 'kjlt', 'info', 'kxyts', 'cxtd', 'yjzx'));
|
||||
$adverts = Advert::where('category_id', 72)->latest('sort')->get();
|
||||
$lt_adverts = Advert::where('category_id', 175)->latest('sort')->get();
|
||||
|
||||
return view('index.index', compact('links', 'adverts', 'lt_adverts'));
|
||||
}
|
||||
|
||||
//通用获取文章
|
||||
public function getArticle($category_ids, $take = 3)
|
||||
{
|
||||
return Article::whereIn('category_id', $category_ids)
|
||||
->select('id', 'description', 'title', 'created_at', 'cover', 'content')
|
||||
->orderBy('created_at', 'desc')
|
||||
->take($take)
|
||||
->get();
|
||||
->select('id', 'description', 'title', 'created_at', 'cover', 'content')
|
||||
->orderBy('created_at', 'desc')
|
||||
->take($take)
|
||||
->get();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user