I want to hide link
@if(Route::has('dashboard.index')) <li class="nav-item"> <a class="nav-link" aria-current="page" href="{{ route('dashboard.index') }}">{{__('My Admin')}}</a> </li> @endif
And if I logged out and in web.php ,i hide route with middlewares (e.g authsanctum and verified):
Route::middleware(['auth:sanctum', 'verified'])->get(['DashContro::class','index])->name('dashboard.index');
.. but the Route::has() is still ‘true’ What to use instead of route has for hiding links while logged out?
Advertisement
Answer
You can conditionally load HTML in blade based on login with the code below. The function Auth::check
returns true if the user is authenticated.
@if(Auth::check()) // only show this if someone is logged in. @endif