<?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()
    {
        return view('index.index');
    }

    //通用获取文章
    public function getArticle($category_ids, $take = 3)
    {
        return Article::latest('sort')
                      ->whereHas('categories', function ($q) use ($category_ids) {
                          $q->where('id', $category_ids);
                      })
                      ->select('id', 'description', 'title', 'created_at', 'cover', 'content')
                      ->latest()
                      ->take($take)
                      ->get();
    }

}
