@extends('layouts.app') @section('title', "Results for '" . $poll->question . "'") @section('content') @if ($voted)
Your vote has been recorded!

@elseif ($alreadyClosed)
The poll is already closed.

@endif @if ($poll->results_visible) @php $sortedOptions = $poll->options->sortByDesc(function($option) use($poll) { return $poll->votes->where('poll_option_id', $option->id)->count(); }); $nonZeroOptions = $sortedOptions->filter(function($option) use($poll) { return $poll->votes->where('poll_option_id', $option->id)->count() > 0; }); $cache = Cache::get($poll->id); $total = $cache['vote_count']; @endphp
@foreach ($sortedOptions as $option) @php ($votes = $poll->votes->where('poll_option_id', $option->id)->count())
{{ $option->text }} : {{ $votes }} votes
{{ $total == 0 ? 0 : round($votes / $total * 100, 2) }}% of votes

@endforeach
Total votes: {{ $total }}
@if ($total != 0)


@foreach ($nonZeroOptions as $option) {{ $option->text }}
@endforeach
@endif
@else
Results for this poll are hidden until the poll is closed.
@endif @endsection