mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-24 20:06:09 +08:00
37 lines
697 B
PHP
37 lines
697 B
PHP
<?php
|
|
|
|
namespace App\Validators;
|
|
|
|
use App\Caches\Tag as TagCache;
|
|
use App\Exceptions\BadRequest as BadRequestException;
|
|
use App\Models\Question as QuestionModel;
|
|
|
|
class QuestionQuery extends Validator
|
|
{
|
|
|
|
public function checkTag($id)
|
|
{
|
|
$tagCache = new TagCache();
|
|
|
|
$tag = $tagCache->get($id);
|
|
|
|
if (!$tag) {
|
|
throw new BadRequestException('question_query.invalid_tag');
|
|
}
|
|
|
|
return $tag->id;
|
|
}
|
|
|
|
public function checkSort($sort)
|
|
{
|
|
$types = QuestionModel::sortTypes();
|
|
|
|
if (!isset($types[$sort])) {
|
|
throw new BadRequestException('question_query.invalid_sort');
|
|
}
|
|
|
|
return $sort;
|
|
}
|
|
|
|
}
|