In my database, i have a list of responses collected from customers that i want to gather and generate a pie chart for. (like that of google forms).
In my database, i have responses that are the same and other not like below
Client 1 Client 2 Client
Yes Yes No
So in the column above, i have Yes(2) and No(1). I want to gather, count and display my query response like below
Yes : 2 , No: 1
But with my code below
public function answers_chart(Survey $survey)
{
$response = DB::select( DB::raw(" select * from (
SELECT questionnaire_id, COUNT(answer) as e_count
FROM Answer
GROUP BY answer
)a where a.e_count > 1));
}
I get the response like below, meaning it is only counting the Yes
[{"e_count":2}]
How can i achieve something like this?
Table
public function up()
{
Schema::create('Answer', function (Blueprint $table) {
$table->increments('id');
$table->integer('question_id');
$table->integer('questionnaire_id');
$table->string('answer');
$table->timestamps();
});
}