artisticre
1 month ago
249
3
Laravel

If Statement in Navbar link

Posted 1 month ago by artisticre

In my Login Controller I have the following logic where it redirects based on role. I want to add the same logic to my navbar to have it redirect to the correct dashboard based on the role. How can I do this?

<a class="dropdown-item" href="@if  @endif">Dashboard</a>

public function redirectTo() 
    {  
         if(Auth::user()->hasRole('registrar')) {
             $this->redirectTo = route('registrar-dashboard');
             return $this->redirectTo;
         } elseif
            (Auth::user()->hasRole('team')) {
                $this->redirectTo = route('team-dashboard');
                return $this->redirectTo;
         
         } elseif 
        (Auth::user()->hasRole('webmaster')) {
            $this->redirectTo = route('webmaster-dashboard');
            return $this->redirectTo;
     } elseif
     (Auth::user()->hasRole('pastor')) {
        $this->redirectTo = route('pastor-dashboard');
        return $this->redirectTo;
     } elseif
     (Auth::user()->hasRole('sponsor')) {
        $this->redirectTo = route('sponsor-dashboard');
        return $this->redirectTo;

    } elseif
    (Auth::user()->hasRole('pilgrim')) {
       $this->redirectTo = route('pilgrim-dashboard');
       return $this->redirectTo;
    } elseif
    (Auth::user()->hasRole('user')) {
       $this->redirectTo = route('user-dashboard');
       return $this->redirectTo;
    }
  return $this->redirectTo;
    }

Please sign in or create an account to participate in this conversation.