@foreach($tickets as $ticket)
{{-- USER ACCESS FILTER --}}
@php
$allowed = true;
// Role 4 & 5 → only show own tickets
if(in_array($role, [4,5]) && $userId != $ticket->user_id){
$allowed = false;
}
// Role 3,6,7 → assigned staff only
if(in_array($role, [3,6,7])){
$assigned = explode(',', $ticket->assigned_staff_id);
if(!in_array($userId, array_map('trim', $assigned))){
$allowed = false;
}
}
// Status filter from request
if(isset($_REQUEST['status']) && !empty($_REQUEST['status'])) {
$requestStatus = $_REQUEST['status'];
// Show ticket if status matches OR status is 4 (Return status always shown)
if($ticket->issue_status != $requestStatus && $ticket->issue_status != '4' && $ticket->issue_status != null) {
$allowed = false;
}
}
@endphp
@if(!$allowed)
@continue
@endif
{{ $ticket->ticket_number }}
@php
$technicianName = '';
$technician = $ticket->technician;
// Role 1 or 2 -> show technician if role is 3, 6, or 7
if ($role == 1 || $role == 2) {
$users = \Illuminate\Support\Facades\DB::table('users')
->whereIn('role', [3, 6, 7])
->where('user_id', $technician)
->first();
if ($users) {
$technicianName = $users->user_name;
}
}
// Role 4, 3, 6, or 5 -> show technician if role is 3
if (in_array($role, [4, 3, 6, 5])) {
$users = \Illuminate\Support\Facades\DB::table('users')
->where('role', 3)
->where('user_id', $technician)
->first();
if ($users) {
$technicianName = $users->user_name;
}
}
// Role 5, 6, or 7 -> show technician if role is 6 or 7
if (in_array($role, [5, 6, 7])) {
$users = \Illuminate\Support\Facades\DB::table('users')
->whereIn('role', [6, 7])
->where('user_id', $technician)
->first();
if ($users) {
$technicianName = $users->user_name;
}
}
@endphp
{{ $technicianName ?: 'N/A' }}