Files
new_ine/app/Http/Controllers/IndexController.php
2020-09-14 14:29:29 +08:00

46 lines
1.5 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Article;
use App\Models\Category;
use App\Models\Link;
class IndexController extends Controller
{
/**
* Notes: 首页
* @Author: 玄尘
* @Date : 2020/6/1 9:11
*/
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'));
}
//通用获取文章
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();
}
}