@php $availableReports = $headOffice->reports() ->where('is_dashboard_report', 1) ->get(); $availableGraphs = $headOffice->allGraphs; $userGraphIds = $headOfficeUser->assignedGraphs?->pluck('graph_type') ->map(fn($id) => (int) $id) ->toArray() ?? []; $userPermissions = $headOfficeUser->get_permissions(); if (!isset($userPermissions->custom_access_rights_id)) { $userPermissions = $headOfficeUser->get_org_profile->profile; $accessibleReportIds = $userPermissions->allowedReports->pluck('id')->toArray(); $userGraphIds = $userPermissions->allowedCharts->pluck('id')->toArray(); $graphAllSites = []; foreach ($userPermissions->allowedCharts as $chart) { $graphAllSites[$chart->id] = $chart->pivot->show_all_sites ?? 0; } $reportAllSites = []; foreach ($userPermissions->allowedReports as $report) { $reportAllSites[$report->id] = $report->pivot->show_all_sites ?? 0; } } else { $accessibleReportIds = $headOfficeUser->accessibleReports->pluck('report_id')->toArray(); $graphAllSites = $headOfficeUser->assignedGraphs?->pluck('show_all_sites', 'graph_type')->toArray() ?? []; $reportAllSites = $headOfficeUser->accessibleReports->pluck('show_all_sites', 'report_id')->toArray(); } @endphp