@extends('layouts.landing') @section('title') {{$poll->name}} @endsection @section('content')
{{$poll->name}}
Add Question
@php $question_no = 1; @endphp @forelse ($questions as $question)
Question {{$question_no++}}

{{$question->title}}

@php $answers = json_decode($question->options); $user_answer = App\Models\PollAnswer::where('user_id', Auth::user()->id)->where('poll_question_id', $question->id)->first(); @endphp @if(isset($user_answer)) @forelse($answers as $key => $answer) @php $answers_count = count($answers); $vote_count = App\Models\PollAnswer::where('poll_question_id', $question->id)->where('choice', $key)->count(); if($vote_count < 1) { $percentage = 0; } else { $percentage = ( 1 / $vote_count ) * 100; } @endphp
{{$answer}} @if($user_answer->choice == $key) @endif {{$percentage}}%
@empty @endforelse @else @forelse($answers as $key => $answer)
{{$answer}}
@empty @endforelse @endif
@empty

You haven't created a poll question
@endforelse
@include('elements.create-poll-question') {{-- @include('elements.create-poll-answer') --}} @endsection