ByCategory(6) ->bysort() ->take(2) ->get();//两个通知公告 $mtbdArticles = Article::shown() ->byCategory(31) ->bysort() ->take(2) ->get(); $nyydtimg = Article::shown() ->byCategory(7) ->whereNotNull('cover') ->bysort() ->take(2) ->get(); $nyydt = Article::shown() ->whereNotIn('id', $nyydtimg->pluck('id')) ->byCategory(7) ->bysort() ->take(4) ->get(); $dzjsimg = Article::shown() ->byCategory($dzjsCate->id) ->whereNotNull('cover') ->bysort() ->first(); $dzjsArticles = Article::shown() ->where('id', '<>', $dzjsimg->id) ->byCategory($dzjsCate->id) ->bysort() ->take(6) ->get(); $xxydimg = Article::shown() ->byCategory($xxydCate->id) ->whereNotNull('cover') ->bysort() ->first(); $xxydArticles = Article::shown() ->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::shown() ->byCategory($info->id) ->whereNotNull('cover') ->bysort() ->first(); $info->imgArticle = $imgArticle; $info->articleLists = Article::shown() ->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')); } }