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);
}
}