I want to hide link
@if(Route::has('dashboard.index'))
<li >
<a 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?
CodePudding user response:
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
CodePudding user response:
Route::has
checks if the route exists, not if it's accessible to the user.
Instead, you should use Blade's @auth
and @guest
directives to show different things for logged-in or logged-out users.
https://laravel.com/docs/8.x/blade#authentication-directives
@auth
// The user is authenticated...
@endauth
@guest
// The user is not authenticated...
@endguest