<?php

namespace App\Http\Controllers;

use App\Models\Advert;
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()
    {

        $top_adverts  = Advert::where('category_id', 33)->latest('sort')->first();
        $cent_adverts = Advert::where('category_id', 33)->latest('sort')->first();

        return view('index.index', compact('top_adverts', 'top_adverts'));
    }

    //通用获取文章
    public function getArticle($category_ids, $take = 3)
    {
        return Article::where('status', 1)
                      ->ByCategory($category_ids)
                      ->select('id', 'description', 'title', 'created_at', 'cover', 'content')
                      ->orderBy('created_at', 'desc')
                      ->take($take)
                      ->get();
    }

}
