Im developing a small app that is able to create surveys, and in these surveys have question, where a question could me a simple input form or in a form of checkboxes.
My issue is related with the multiple values (radio inputs), i have a table called "answers" with the above structure:
Answers (table):
- id;
- question_id;
- answer;
- email;
In one of my backend pages i have a table where i loop the question and the answers.
Is working fine, but the problem is when i have multiple values, the header table (questions) starts being less the the coluns body answers, and this is because of the number of answers.
I created this query using eloquent and collection where first i orderByGroup of 'email'.
$survey = Survey::find($id);
return $survey->answers->groupBy('email');
It gives me a array of grouped answers from each email, this is great, but now i need to group inside the email groups the questions, in my case 'question_id'. But isnt working for me.
I tried something like
return $survey->answers->groupBy('email')->groupBy('question_id');
But it doesnt work.