Reputation: 129
in my navbar i want to allow upload link for admin role and download for user role i got this error ... thats my blade.php file
@if (Route::has('register'))
@if(auth::user()->user)
<li class="nav-item">
<a class="nav-link" href="{{ route('download') }}">{{ __('download') }}</a>
</li>
@endif
@else
<li class="nav-item ">
<a class="nav-link capital" href="{{ route('upload') }}">{{ __('upload') }}</a>
</a>
@endif
@endif
Upvotes: 0
Views: 84
Reputation: 12391
you can use @auth @endauth
@auth
<li class="nav-item">
<a class="nav-link" href="{{ route('download') }}">{{ __('download') }}</a>
</li>
@endauth
ref link https://laravel.com/docs/8.x/blade#authentication-directives
Upvotes: 1
Reputation: 4201
alernative you can use optional
global helper
optional(Auth::user())->$anyProperty;
Upvotes: 0
Reputation: 4153
If you user is guest then you have no record on DB, so first check if has been authenticated or not.
change this line:
@if(auth::user()->user)
to this
@if(Auth::check())
Upvotes: 1