<?php

namespace app\traits;

use think\Model;
use app\model\Category;
use think\db\exception\DbException;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;

trait CmsCategoryTrait
{
    /**
     * 获取栏目
     *
     * @param  string  $name
     * @return array|Model|null
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function getCategoryByName(string $name)
    {
        return Category::where('name', $name)->find();
    }

    /**
     * 获取栏目
     *
     * @param  int  $id
     * @return array|Model|null
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function getCategoryById(int $id)
    {
        return Category::findById($id);
    }
}