I am new to Laravel. I am now able to register users, log them in. But after login, I don't want to display register and login pages. I want to display logout link. This is easy for me with core php. I want something similar like the one below.
<?php
if(isset($_SESSION['id'])){
?>
<a href="index.php">Home</a>
<a href="dashboard.php">Dashboard</a>
<a href="logout.php">Logout</a>
<?php
}else{
?>
<a href="index.php">Home</a>
<a href="register.php">Register</a>
<a href="login">Login</a>
<?php
}
?>
CodePudding user response:
Blade has @auth, which checks if user is logged in or not
@auth
/* what logged in users should see */
@else
/* what guests should see */
@endauth
Also has @guest (ending with @endguest) which does the opposite.
And if you named your routes, you can for example:
href="{{route('login')}}"
This way the url changes if you change your routes.
CodePudding user response:
@if(Auth::user())
<button>I'm logged in</button>
@else
<button>I'm not logged in </button>
@endif