gpt4 book ai didi

php - Laravel:ERR_TOO_MANY_REDIRECTS

转载 作者:可可西里 更新时间:2023-10-31 23:15:20 26 4
gpt4 key购买 nike

我正在尝试在 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']);
});
});

});

});

着陆 Controller :

<?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 函数只返回 View ,我认为如果我发布整个类,它只是用代码过多地发送问题,所以我只是解释了它是如何绘制图片的

最佳答案

你有你的家路线的名字,和你的登录路线一样。

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

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

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

关于php - Laravel:ERR_TOO_MANY_REDIRECTS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46435866/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com