@php
// Check if responses are already arrays
$adminResponses = is_array($ticket->admin_responses) ?
$ticket->admin_responses :
(json_decode($ticket->admin_responses, true) ?? []);
$userReplies = is_array($ticket->user_replies) ?
$ticket->user_replies :
(json_decode($ticket->user_replies, true) ?? []);
// Combine both arrays and sort by timestamp
$allResponses = [];
foreach($adminResponses as $response) {
$response['type'] = 'admin';
$allResponses[] = $response;
}
foreach($userReplies as $reply) {
$reply['type'] = 'user';
$allResponses[] = $reply;
}
// Sort by timestamp (newest first)
usort($allResponses, function($a, $b) {
return strtotime($b['timestamp']) - strtotime($a['timestamp']);
});
@endphp
@if(count($allResponses) > 0)
@foreach($allResponses as $response)
@if($response['type'] === 'admin')
Admin
{{ \Carbon\Carbon::parse($response['timestamp'])->format('d M Y H:i') }}
{{ $response['notes'] ?? '' }}
@if(isset($response['photo']))
@endif
@else
Anda
{{ \Carbon\Carbon::parse($response['timestamp'])->format('d M Y H:i') }}
@if(isset($response['message']))
{{ $response['message'] }}
@elseif(isset($response['notes']))
@if(isset($response['type']) && $response['type'] === 'confirm')
Dikonfirmasi selesai
@elseif(isset($response['type']) && $response['type'] === 'reject')
Masih ada masalah
@endif
{{ $response['notes'] }}
@endif
@if(isset($response['photo']) && !empty($response['photo']))
@endif
@endif
@endforeach
@else
Belum Ada Respon
Tiket ini belum memiliki balasan dari admin atau pengguna
@endif