1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-24 04:01:31 +08:00
koogua 0336a54911 1.源文件增加版权信息
2.群组状态和课程协同
2021-06-13 15:49:47 +08:00

56 lines
1.2 KiB
PHP

<?php
/**
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.koogua.com
*/
namespace App\Validators;
use App\Caches\Category as CategoryCache;
use App\Caches\Tag as TagCache;
use App\Exceptions\BadRequest as BadRequestException;
use App\Models\Article as ArticleModel;
class ArticleQuery extends Validator
{
public function checkCategory($id)
{
$categoryCache = new CategoryCache();
$category = $categoryCache->get($id);
if (!$category) {
throw new BadRequestException('article_query.invalid_category');
}
return $category->id;
}
public function checkTag($id)
{
$tagCache = new TagCache();
$tag = $tagCache->get($id);
if (!$tag) {
throw new BadRequestException('article_query.invalid_tag');
}
return $tag->id;
}
public function checkSort($sort)
{
$types = ArticleModel::sortTypes();
if (!isset($types[$sort])) {
throw new BadRequestException('article_query.invalid_sort');
}
return $sort;
}
}