Laravel:ERR_TOO_MANY_REDIRECTS

时间:2017-09-26 21:08:15

标签: php laravel

我正在尝试在Laravel中编写基本身份验证系统,从而导致重定向循环。

首先,我只是访问“localhost”域,然后在我甚至未经过身份验证时将其发送到/ home并抛出chrome错误。

路线:     

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');
    }
}

LoginController和HomeController函数只返回视图,我认为如果我发布整个类,它只是用代码过多地发送垃圾邮件问题,所以我只是解释了它为绘制图片做了什么

1 个答案:

答案 0 :(得分:3)

您拥有自己路线的名称,与您的登录路线相同。

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

你可以通过给它自己的名字来解决这个问题,就像这样。

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