@php
$user = auth()->user();
$roleName = $user->nama_role
?? $user->role_name
?? null;
$roleId = null;
if ($user) {
$roleId = (int) ($user->id_role ?? $user->role_id ?? 0);
}
if (!$roleName && $roleId > 0) {
try {
if (\Illuminate\Support\Facades\Schema::hasTable('role')) {
$roleName = \Illuminate\Support\Facades\DB::table('role')->where('id_role', $roleId)->value('nama_role');
}
} catch (Throwable $e) {
$roleName = null;
}
}
$roleName = (string) ($roleName ?: 'User');
$roleKey = strtolower($roleName);
$isSuperadmin = $roleId === 1 || str_contains($roleKey, 'super');
$isDirektur = $roleId === 2 || str_contains($roleKey, 'direktur');
$isManagerTeknik = $roleId === 3
|| str_contains($roleKey, 'manager tehnik')
|| str_contains($roleKey, 'manager teknik')
|| str_contains($roleKey, 'project manager')
|| str_contains($roleKey, 'kepala divisi tehnik')
|| str_contains($roleKey, 'kepala divisi teknik')
|| str_contains($roleKey, 'kadiv tehnik')
|| str_contains($roleKey, 'kadiv teknik');
$isManagerKeuangan = $roleId === 4
|| str_contains($roleKey, 'manager administrasi')
|| str_contains($roleKey, 'manager keuangan')
|| str_contains($roleKey, 'kepala divisi administrasi')
|| str_contains($roleKey, 'kepala divisi keuangan')
|| str_contains($roleKey, 'kadiv administrasi')
|| str_contains($roleKey, 'kadiv keuangan');
$isStaffSales = $roleId === 5 || str_contains($roleKey, 'sales');
$isStaffTeknik = $roleId === 6
|| str_contains($roleKey, 'staf tehnik')
|| str_contains($roleKey, 'staff tehnik')
|| str_contains($roleKey, 'staf teknik')
|| str_contains($roleKey, 'staff teknik');
$isStaffKeuangan = $roleId === 7
|| str_contains($roleKey, 'staf administrasi')
|| str_contains($roleKey, 'staff administrasi')
|| str_contains($roleKey, 'staf keuangan')
|| str_contains($roleKey, 'staff keuangan')
|| str_contains($roleKey, 'admin kantor');
$routeUrl = function (?string $route, string $fallback = '#') {
return $route && \Illuminate\Support\Facades\Route::has($route) ? route($route) : $fallback;
};
$routeActive = function ($patterns) {
foreach ((array) $patterns as $pattern) {
if (request()->routeIs($pattern)) {
return 'active';
}
}
return '';
};
$renderLink = function (string $icon, string $label, ?string $route = null, $activePatterns = [], string $fallback = '#') use ($routeUrl, $routeActive) {
$href = $routeUrl($route, $fallback);
$active = $routeActive($activePatterns ?: ($route ? [$route] : []));
return ''.$icon.''.e($label).'';
};
@endphp