<?php

namespace App\Services\Deed;

use App\Models\Invite\QuestionTagModel;
use App\Models\Invite\QuestionTemplateModel;

class QuestionService
{

    /**
     * 获取标签列表
     * @return \Illuminate\Support\Collection
     */
    public function tags()
    {
        $tags = QuestionTagModel::get(['tag']);

        return $tags;
    }


    /**
     * 获取标签的问题
     * @param  string  $tag_id
     * @return \Illuminate\Support\Collection
     */
    public function getQuestion($tag_id = '')
    {
        $questions = QuestionTemplateModel::when($tag_id, function ($query) use ($tag_id) {
            return $query->where('tag_id', $tag_id);
        })->get(['id', 'type', 'question', 'tag_id', 'author']);

        return $questions;
    }
}
