QuestionService.php 768 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Services\Deed;
  3. use App\Models\Invite\QuestionTagModel;
  4. use App\Models\Invite\QuestionTemplateModel;
  5. class QuestionService
  6. {
  7. /**
  8. * 获取标签列表
  9. * @return \Illuminate\Support\Collection
  10. */
  11. public function tags()
  12. {
  13. $tags = QuestionTagModel::get(['tag']);
  14. return $tags;
  15. }
  16. /**
  17. * 获取标签的问题
  18. * @param string $tag_id
  19. * @return \Illuminate\Support\Collection
  20. */
  21. public function getQuestion($tag_id = '')
  22. {
  23. $questions = QuestionTemplateModel::when($tag_id, function ($query) use ($tag_id) {
  24. return $query->where('tag_id', $tag_id);
  25. })->get(['id', 'type', 'question', 'tag_id', 'author']);
  26. return $questions;
  27. }
  28. }