简体   繁体   中英

Laravel: ERR_TOO_MANY_REDIRECTS

I'm trying to code a basic authentication system in Laravel, its resulting in a redirect loop.

First I just visit the "localhost" domain, it then sends me to /home when I'm not even authenticated and throws the chrome error.

Routes:

Route::group(['middleware' => 'platform', 'namespace' => 'Ec9'], function() {

    Route::group(['prefix' => 'platform'], function() {
        Route::get('/restricted', ['as' => 'platform.restricted', 'uses' => 'PlatformController@getRestrictedView']);
        Route::get('/unlock_route', ['as' => 'platform.unlock_route', 'uses' => 'PlatformController@getUnlockRouteView']);
    });

    Route::group(['domain' => 'localhost', 'midleware' => 'frontend', 'namespace' => 'Frontend'], function() {

        Route::group(['middleware' => 'guest', 'namespace' => 'Guest'], function() {

            Route::group(['prefix' => 'setup'], function() {
                Route::any('/language', ['as' => 'frontend.guest.setup.language', 'uses' => 'LandingController@getSetupLanguageView']);
                Route::any('/welcome', ['as' => 'frontend.guest.setup.welcome', 'uses' => 'LandingController@getSetupWelcomeView']);
            });

            Route::get('/', ['as' => 'frontend.guest.landing', 'uses' => 'LandingController@redirect']);

            Route::get('/login', ['as' => 'frontend.guest.login', 'uses' => 'LoginController@getLoginView']);
            Route::post('/login', ['as' => 'frontend.guest.login', 'uses' => 'LoginController@onLoginPost']);

        });

        Route::group(['middleware' => 'auth', 'namespace' => 'User'], function() {
            Route::get('/home', ['as' => 'frontend.guest.login', 'uses' => 'HomeController@getHomeView']);

            Route::group(['prefix' => 'account'], function() {
                Route::get('/logout', ['as' => 'frontend.user.account.logout', 'uses' => 'AccountController@logout']);
                Route::get('/settings', ['as' => 'frontend.user.account.settings', 'uses' => 'AccountController@getAccountSettingsView']);
            });
        });

    });

});

LandingController:

<?php
namespace App\Http\Controllers\Ec9\Frontend\Guest;

use App\Http\Controllers\Controller;
use Redirect;
use Auth;

class LandingController extends Controller
{
    public function redirect() {
        if (Auth::check()) {
            return redirect()->route('frontend.user.home');
        }

        return redirect()->route('frontend.guest.login');
    }
}

And the LoginController and HomeController functions just return the views, I thought it was just spamming the question with code too much if I posted the whole class, so I just explained what it did to paint a picture

You have the name of your home route, the same as your login route.

Route::get('/home', ['as' => 'frontend.guest.login', 'uses' => 'HomeController@getHomeView']);

You can fix this by giving it its own name, something like this.

Route::get('/home', ['as' => 'frontend.user.home', 'uses' => 'HomeController@getHomeView']);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM