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/zelfverkopen.komma.pro/app/KommaApp/Questions/HowItWorksComposer.php
<?php


namespace App\KommaApp\Questions;


use App\KommaApp\Questions\Models\Question;
use Illuminate\View\View;

class HowItWorksComposer
{
    /**
     * Bind data to the view.
     *
     * @param  View $view
     * @return void
     */
    public function compose(View $view)
    {
        $stepsAmount = 4;
        $questionIdForSteps = [];

        for($i = 1; $i <= $stepsAmount; $i++){
            $questionIds = \DB::table('block_questions')
                ->where('block_code_name', 'process_'.$i)
                ->orderBy('id')
                ->pluck('question_id');

            $questionIdForSteps['process_'.$i] = $questionIds;
        }

        $questions = [];
        foreach ($questionIdForSteps as $group => $ids){

            $questionGroup = Question::where('active', 1)
                ->orderBy('lft')
                ->with('translation')
                ->whereIn('id', $ids)
                ->get();

            $orderedQuestions = collect();
            foreach ($ids as $questionId)  $orderedQuestions->push($questionGroup->where('id', $questionId)->first());

            $questions[$group] = $orderedQuestions;
        }

        $view->with('questions', $questions);
    }
}