@extends('layouts.app') @section('title', "Results for '" . $poll->question . "'") @section('content') @if ($voted)
Your vote has been recorded!
@endif @if($poll->results_visible) @php ($sortedOptions = $poll->options->sortByDesc(function($option) use($poll) { return $poll->votes->where('poll_option_id', $option->id)->count(); })) @php ($nonZeroOptions = $sortedOptions->filter(function($option) use($poll) { return $poll->votes->where('poll_option_id', $option->id)->count() > 0; }))
@php ($total = $poll->votes->count()) @foreach ($sortedOptions as $option) @php ($votes = $poll->votes->where('poll_option_id', $option->id)->count())
{{ $option->text }} {{ $votes }} votes
@endforeach
Total votes: {{ $total }}
@php ($cache = Cache::get($poll->id))

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