@extends('layouts.content') @section('content')
Kembali

Beri Ulasan

Pesanan: {{ $order->invoice_number }}

Selesai
@if (session('error'))
{{ session('error') }}
@endif @if (session('success'))
{{ session('success') }}
@endif {{-- Produk yang sudah diulas --}} @php $allProductIds = $order->details->pluck('package.product_id')->unique()->values(); @endphp {{-- 1. Tampilkan produk yang sudah diulas (read-only & form edit) --}} @foreach($allProductIds as $productId) @php $detail = $order->details->firstWhere('package.product_id', $productId); $prod = $detail?->package?->product; $alreadyReviewed = isset($existingReviews[$productId]); $existingReview = $alreadyReviewed ? $existingReviews[$productId] : null; // Photo $photoUrl = asset('assets/img/selada.png'); if ($prod && $prod->media->isNotEmpty()) { $mainMedia = $prod->media->firstWhere('is_main', true) ?? $prod->media->first(); $ext = strtolower(pathinfo($mainMedia->getRawOriginal('file_url'), PATHINFO_EXTENSION)); if (in_array($ext, ['jpg','jpeg','png','webp','gif','heic'])) { $photoUrl = $mainMedia->file_url; } } @endphp @if($alreadyReviewed)
@php $rv = $existingReview; @endphp {{-- Tampilan ulasan yang sudah diberikan (read-only) --}}
{{ $prod->product_name ?? '-' }}
{{ $prod->product_name ?? '-' }}
Sudah diulas
{{-- Rating stars --}}
@for($i = 1; $i <= 5; $i++) @endfor {{ $rv->rating }}/5
@if($rv->comment)

{{ $rv->comment }}

@endif {{-- Media existing --}} @if($rv->media->isNotEmpty())
@foreach($rv->media as $media) @if($media->media_type === 'photo')
Review photo
@else
@endif @endforeach
@endif {{-- Tombol Edit --}}
{{-- Form Edit Ulasan (hidden by default) --}}
@endif @endforeach {{-- 2. Form Master untuk semua produk yang BELUM diulas --}} @php $unreviewedIds = $allProductIds->filter(fn($id) => !isset($existingReviews[$id])); @endphp @if($unreviewedIds->count() > 0)
@csrf @foreach($unreviewedIds as $productId) @php $detail = $order->details->firstWhere('package.product_id', $productId); $prod = $detail?->package?->product; $photoUrl = asset('assets/img/selada.png'); if ($prod && $prod->media->isNotEmpty()) { $mainMedia = $prod->media->firstWhere('is_main', true) ?? $prod->media->first(); $ext = strtolower(pathinfo($mainMedia->getRawOriginal('file_url'), PATHINFO_EXTENSION)); if (in_array($ext, ['jpg','jpeg','png','webp','gif','heic'])) { $photoUrl = $mainMedia->file_url; } } @endphp
{{ $prod->product_name ?? '-' }}
{{ $prod->product_name ?? '-' }}
Varian: {{ $detail->package->weight_in_kg ? $detail->package->weight_in_kg . ' Kg' : '-' }}
{{-- Rating --}}
@error("reviews.{$productId}.rating")
{{ $message }}
@enderror
{{-- Comment --}}
@error("reviews.{$productId}.comment")
{{ $message }}
@enderror
{{-- Media Upload --}}
Tambah Media
Format: JPG, PNG, GIF, WEBP, MP4, MOV. Maks 20MB per file. @error("media_{$productId}.*")
{{ $message }}
@enderror
@endforeach
@endif
@endsection