<?php

namespace App\Http\Controllers;

use App\Models\Advert;
use App\Models\Article;
use App\Models\Link;

class IndexController extends Controller
{

    /**
     * Notes: 首页
     * @Author: 玄尘
     * @Date  : 2020/6/1 9:11
     */
    public function index()
    {
        $adverts     = Advert::where('category_id', 22)->get();
        $description = Article::find(255);
        $oneNews     = Article::where('category_id', 7)->orderBy('created_at', 'desc')->first();
        $news        = Article::where('category_id', 7)->where('id', '<', $oneNews->id)->orderBy('created_at', 'desc')->take(4)->get();
        $articles    = Article::where('category_id', 19)->orderBy('created_at', 'desc')->take(4)->get();
        $prizes      = Article::where('category_id', 20)->orderBy('created_at', 'desc')->take(8)->get();
        $patents     = Article::where('category_id', 21)->orderBy('created_at', 'desc')->take(3)->get();
        $leaders     = Article::where('category_id', 4)->take(3)->get();
        $simples     = Article::where('category_id', 6)->take(6)->get();
        $links       = Link::take(6)->get();

        return view('index.index', compact('adverts', 'description', 'oneNews', 'news', 'articles', 'prizes', 'patents', 'leaders', 'simples', 'links'));
    }

}
