I have a navigation bar that I want to show a link to the admin dashboard. If the user is logged in then admin is if not , Then he should not show anything to me. I have the same set with similar guests.
@if (athe :: guest ()) & lt; Li & gt; & Lt; A href = "{{url ('/ auth / login')}}" & gt; Login & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "{{url ('/ auth / register')}}" & gt; Register & lt; / A & gt; & Lt; / Li & gt; @ Ban & lt; Li class = "dropdown" & gt; & Lt; A href = "#" class = "dropdown-toggle" data-toggle = "dropdown" role = "button" aria-expanded = "false" & gt; {{AUTH :: User () - & gt; Name}} & lt; Span class = "carat" & gt; & Lt; / Span & gt; & Lt; / A & gt; & Lt; Ul class = "dropdown-menu" role = "menu" & gt; & Lt; Li & gt; & Lt; A href = "{{url ('/ profile')}}" & gt; Profile & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "{{url ('/ auth / logout')}}" & gt; Logout & lt; / A & gt; & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Li & gt; @endif
But how can I do this for a logged in user and administrator? I am currently
& lt; Ul class = "nav navbar-nav" & gt; & Lt; Li & gt; & Lt; A href = "{{url ('/')}} & gt; Home & lt; / a & gt; & lt; / li & gt; @f (athe :: guest ()) @ELSE & lt; li & Gt; & lt; a href = "{{url ('/ admin'}}}" & gt; Admin Dashboard & lt; / a & gt; & lt; / li & gt; @Endif & lt; / ul & Gt;
I have middleware set on the administrator path like
get root: get ('admin', ['middleware' = & gt; ;);
that looks
public function handles ($ $ request; $ admin ;, 'use' = & gt; 'AdminController @ index']) Closure $ next) {If ($ request-> User () -> Geo Mika! = 1) {return redirection ('home');} $ next ($ request) return;}
And it's okay, I do not know how this one of the blade templates Define the part.
It appears that your user model has the role
Name is a feature, so you can do something like this:
& lt; ul class = "nav navbar-nav" & gt; & Lt; Li & gt; & Lt; A href = "{{url ('/')}} & gt; Home & lt; / a & gt; & lt; / li & gt; @if (Ath :: user) - & gt; Role! = 1 ) {{- I am not an admin user}} @else {{- I am an administrator user}}} @ adif
If this is your case You need to add a new feature to the user model, in this way, you can emulate the above code.
For better code structure and order, I suggest that If you like this Rate a file:
Public function is admin () {returns (\ AUTH :: check () and $ this-> role == 1}}
or any other to check whether it is a regular user:
/ ** A user who is certified but not an administrator / / public Function is Regular () Returns (\ AUTH :: Inquiry () & amp; $ this-> Role! = 1);}
After that, You may like them:
@if (Au Th :: user) - & gt; IsRegular ()) {{- I am not an admin user}} @else {{- I am an administrator user}} @Adif
or
@if (Ath :: User) - & gt; Iadmin ()) {{- I am an administrator user}} @else {{- I am not an administrator user}} @Endif
No comments:
Post a Comment