Commit df5985a9 authored by LucBUTGH's avatar LucBUTGH
Browse files

fix: roles in dropdown menu

parent 054d261d
Loading
Loading
Loading
Loading
+15 −0
Changes for app/Http/Controllers/HeaderController.php: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\User;

class HeaderController extends Controller
{
    function index(): View
    {
        $roles = User::getRole();
        return view('components/header', ['roles' =>$roles]);
    }
}
+0 −11
Changes for app/Models/User.php: 0 added lines, 11 removed lines.
Original line number Diff line number Diff line
@@ -45,17 +45,6 @@ public function roles()
        return $this->belongsToMany(Role::class, RoleAttribution::class, 'US_ID', 'ROL_CODE');
    }

    public function getRole() {
        return User::select('CAR_ROLE.ROL_LABEL')
            ->join('CAR_ROLE_ATTRIBUTION', 'CAR_USER.US_ID', '=', 'CAR_ROLE_ATTRIBUTION.US_ID')
            ->join('CAR_ROLE', 'CAR_ROLE_ATTRIBUTION.ROL_CODE', '=', 'CAR_ROLE.ROL_CODE')
            ->where('CAR_USER.US_ID',session('user')->US_ID)
            ->pluck('CAR_ROLE.ROL_LABEL')
            ->first();    }
    
    
    

    /**
     * Check if the user has a given role.
     *
+1 −1
Changes for resources/views/components/header.blade.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ class="w-8 h-8 rounded-full py-2 font-bold text-white">{{ substr(session('user')
                    <div class="px-4 py-3">
                        <span
                            class="block text-sm text-white">{{ session('user')->US_FIRST_NAME . " " . session('user')->US_NAME }}</span>
                            <span class="mb-2 mt-2 italic block text-sm truncate text-white">{{ session('user')->getRole() }}</span>
                            <span class="mb-2 mt-2 italic block text-sm truncate text-white">    {{ session('user')->roles()->pluck('ROL_LABEL')->implode(' - ') }}</span>

                            <span class="block text-sm truncate text-gray-400">{{ session('user')->US_EMAIL }}</span>