二次改版
This commit is contained in:
@@ -4,19 +4,134 @@ namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Advert;
|
||||
use App\Models\Article;
|
||||
use App\Models\Category;
|
||||
use App\Models\Link;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class IndexController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Notes: 首页
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/6/1 9:11
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('index.index');
|
||||
$nyydtCate = Category::find(7);//能源院动态
|
||||
$mtbdCate = Category::find(31);//媒体报道
|
||||
$dzjsCate = Category::find(28);//党政建设
|
||||
$xxydCate = Category::find(9);//学习园地
|
||||
|
||||
$notices = Article::query()
|
||||
->ByCategory(6)
|
||||
->bysort()
|
||||
->take(2)
|
||||
->get();//两个通知公告
|
||||
|
||||
|
||||
$mtbdArticles = Article::query()
|
||||
->byCategory(31)
|
||||
->bysort()
|
||||
->take(2)
|
||||
->get();
|
||||
|
||||
|
||||
$nyydtimg = Article::query()
|
||||
->byCategory(7)
|
||||
->whereNotNull('cover')
|
||||
->bysort()
|
||||
->take(2)
|
||||
->get();
|
||||
|
||||
$nyydt = Article::query()
|
||||
->whereNotIn('id', $nyydtimg->pluck('id'))
|
||||
->byCategory(7)
|
||||
->bysort()
|
||||
->take(4)
|
||||
->get();
|
||||
|
||||
$dzjsimg = Article::query()
|
||||
->byCategory($dzjsCate->id)
|
||||
->whereNotNull('cover')
|
||||
->bysort()
|
||||
->first();
|
||||
|
||||
$dzjsArticles = Article::query()
|
||||
->where('id', '<>', $dzjsimg->id)
|
||||
->byCategory($dzjsCate->id)
|
||||
->bysort()
|
||||
->take(6)
|
||||
->get();
|
||||
|
||||
$xxydimg = Article::query()
|
||||
->byCategory($xxydCate->id)
|
||||
->whereNotNull('cover')
|
||||
->bysort()
|
||||
->first();
|
||||
|
||||
$xxydArticles = Article::query()
|
||||
->where('id', '<>', $xxydimg->id)
|
||||
->byCategory($xxydCate->id)
|
||||
->bysort()
|
||||
->take(6)
|
||||
->get();
|
||||
|
||||
$advert = Advert::query()->where('category_id', 36)->first();
|
||||
|
||||
$categorys = Category::oldest('order')->find([20, 21, 24]);//成果
|
||||
$categorys = $categorys->map(function ($info) {
|
||||
$imgArticle = Article::query()
|
||||
->byCategory($info->id)
|
||||
->whereNotNull('cover')
|
||||
->bysort()
|
||||
->first();
|
||||
$info->imgArticle = $imgArticle;
|
||||
$info->articleLists = Article::query()
|
||||
->where('id', '<>', $imgArticle->id)
|
||||
->byCategory($info->id)
|
||||
->bysort()
|
||||
->take(4)
|
||||
->get();
|
||||
return $info;
|
||||
});
|
||||
|
||||
|
||||
$data = compact(
|
||||
'categorys',
|
||||
'xxydCate',
|
||||
'mtbdCate',
|
||||
'nyydtCate',
|
||||
'dzjsCate',
|
||||
'notices',
|
||||
'mtbdArticles',
|
||||
'xxydArticles',
|
||||
'dzjsArticles',
|
||||
'nyydt',
|
||||
'dzjsimg',
|
||||
'xxydimg',
|
||||
'advert',
|
||||
'nyydtimg'
|
||||
);
|
||||
return view('index.index', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 搜索
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2022/6/29 10:14
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function search(Request $request)
|
||||
{
|
||||
$title = $request->title;
|
||||
$articles = Article::query()->latest()->where('title', 'like', "%{$title}%")->paginate();
|
||||
|
||||
return view('index.search', compact('articles'));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user