This commit is contained in:
Codex
2026-07-10 11:18:07 -05:00
parent 42db078e47
commit e5a95a0687
32 changed files with 471 additions and 11 deletions
@@ -0,0 +1,21 @@
@props(['type', 'id', 'category' => 'overall', 'mode' => 'stars'])
@auth
<form method="POST" action="{{ route('ratings.store') }}" class="mt-4 space-y-3 rounded border p-4">
@csrf
<input type="hidden" name="rateable_type" value="{{ $type }}">
<input type="hidden" name="rateable_id" value="{{ $id }}">
<input type="hidden" name="category" value="{{ $category }}">
@if ($mode === 'thumbs')
<label class="block text-sm font-medium">Vote</label>
<select name="thumbs_up" class="rounded-md border-gray-300">
<option value="1">Thumbs up</option>
<option value="0">Thumbs down</option>
</select>
@else
<x-field name="stars" label="Stars 1-5" type="number" />
@endif
<x-field name="body" label="Reason" textarea />
<x-primary-button>Save rating</x-primary-button>
</form>
@endauth
@@ -0,0 +1,25 @@
@props(['ratings'])
@php
$starRatings = $ratings->whereNotNull('stars');
$thumbRatings = $ratings->whereNotNull('thumbs_up');
$average = $starRatings->count() ? round($starRatings->avg('stars'), 1) : null;
$up = $thumbRatings->where('thumbs_up', true)->count();
$down = $thumbRatings->where('thumbs_up', false)->count();
@endphp
<div class="mt-4 rounded border bg-gray-50 p-4 text-sm">
<p class="font-semibold">Community rating</p>
<p class="mt-1 text-gray-700">
Stars: {{ $average ? $average.'/5' : 'n/a' }} from {{ $starRatings->count() }} vote{{ $starRatings->count() === 1 ? '' : 's' }}
| Thumbs: {{ $up }} up / {{ $down }} down
</p>
@foreach ($ratings->take(5) as $rating)
@php
$value = $rating->stars
? $rating->stars.'/5'
: ($rating->thumbs_up === null ? 'no vote' : ($rating->thumbs_up ? 'thumbs up' : 'thumbs down'));
@endphp
<p class="mt-2 text-gray-600">{{ $rating->user->name ?? 'User' }} | {{ $rating->category }} | {{ $value }} {{ $rating->body ? '- '.$rating->body : '' }}</p>
@endforeach
</div>