Search code examples
phplaravelrouteslaravel-5.3controllers

Laravel 5.3 Cannot find login page


I am just beginning to learn laravel and I have been looking all over for this answer. I was following a tutorial step by step to get it started and I have it running the welcome screen but if I click login or register it says that the file doesnt exist. However if I make the route.

Route::get('/', function() {
    return view('auth/login');
});

It finds the page and displays it.

here is the link to the login page.

<div class="panel panel-success">
            <div class="panel-heading">List of Game of Thrones Characters</div>

                @if(Auth::check())
                  <p>Success</p>
                @endif


        </div>
        <?php
             echo getcwd() . "\n";
        ?>

        @if(Auth::guest())
          <a href="/login" class="btn btn-info"> You need to login to see the list 😜😜 >></a>
        @endif

In the href tag I have tried /auth/login, /login, and any combo you can try and it will not find the file no matter what. Here is the route I am trying to get this to work.

Route::get('/login', function() {
   return view('auth/login');
}

Can anyone explain why this isnt working? I have looked everywhere and it seems to be the correct way to call this. Remember I have just gotten the beginning templates to work.


Solution

  • You need to setup web server rewrites in your webserver.

    The simplest way to handle that is to use a .htaccess file in your public/ directory. This is the default .htaccess file for Laravel 5.3:

    <IfModule mod_rewrite.c>
        <IfModule mod_negotiation.c>
            Options -MultiViews
        </IfModule>
    
        RewriteEngine On
    
        # Redirect Trailing Slashes If Not A Folder...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)/$ /$1 [L,R=301]
    
        # Handle Front Controller...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]
    
        # Handle Authorization Header
        RewriteCond %{HTTP:Authorization} .
        RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    </IfModule>
    

    You also need to ensure that the mod_rewrite Apache module is enabled. You can do that by running these two commands which enable the module and restart Apache:

    a2enmod rewrite
    service apache2 restart