0

I am new to Laravel and I am confused with these snippets that I got automatically when I installed the laravel UI by using the command compose require laravel/ui I am not quite getting what it's trying to do.

@if (Route::has('login'))
    <div class="top-right links">
        @auth
            <a href="{{ url('/home') }}">Home</a>
        @else
            <a href="{{ route('login') }}">Login</a>
            @if (Route::has('register'))
                <a href="{{ route('register') }}">Register</a>
            @endif
        @endauth
    </div>
@endif
Karl Hill
  • 12,937
  • 5
  • 58
  • 95
A.M.Usmani
  • 23
  • 7

2 Answers2

0

In English, it's saying that if you have laravel/ui installed and Auth::routes() in the web.php routes file then if you also logged in (authenticated) show the "Home" link. Otherwise, if you are not logged in, show the login link and then if there is a route for 'register' then display the register link. You can verify your current routes from the command line by issuing: php artisan route:list.

Karl Hill
  • 12,937
  • 5
  • 58
  • 95
0

The code snippet is just to show the Menu Link based on whether you are logged in or not

 @if (Route::has('login'))
    <div class="top-right links">
        @auth
            <a href="{{ url('/home') }}">Home</a>
        @else
            <a href="{{ route('login') }}">Login</a>
            @if (Route::has('register'))
                <a href="{{ route('register') }}">Register</a>
            @endif
        @endauth
    </div>
@endif

In the above code snippet @if (Route::has('login')) It just checks if you have any route that is registered with name login if yes

@auth this one checking if you are already logged in then it will show 'Home' link else it will show 'Login' link

@if (Route::has('register')) this one again checking if you have any route defined with name register then it will also show 'Register' link as well

Anku Singh
  • 914
  • 6
  • 12