Php 如何在laravel中对该层进行身份验证;不创建循环?

Php 如何在laravel中对该层进行身份验证;不创建循环?,php,laravel,Php,Laravel,好的,这里有一个路由,我已经启用了laravel身份验证 Auth::routes(); Route::get('/{catchall?}', 'HomeController@index')->name('home')->where('catchall', '.*'); 我有一个疑问。当我们到达/注册我的Larvel的路线时,我们通过了两个中间件 web和guest。我对guest中间件有疑问。比如它怎么不产生循环 好的,现在假设我已通过身份验证并登录。现在我走上了注册路线。它将通

好的,这里有一个路由,我已经启用了laravel身份验证

Auth::routes();
Route::get('/{catchall?}', 'HomeController@index')->name('home')->where('catchall', '.*');
我有一个疑问。当我们到达/注册我的Larvel的路线时,我们通过了两个中间件
web
guest
。我对
guest
中间件有疑问。比如它怎么不产生循环

好的,现在假设我已通过身份验证并登录。现在我走上了注册路线。它将通过来宾中间件,如下所示:

   public function handle($request, Closure $next, $guard = null)
    {
        if (Auth::guard($guard)->check()) { 
            return redirect('/home');
        }

        return $next($request);
    }
因为我已经登录了。Laravel会将我重定向到“/家”。现在我要去HomeController@index方法,但在此之前,我将通过中间件
auth
作为HomeController的内部构造方法

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index()
    {
        return view('home');
    }
 }
因此,在呈现
视图('home')
之前,我将再次传递给auth中间件。这是
auth
中间件

class Authenticate extends Middleware
{
    /**
     * Get the path the user should be redirected to when they are not authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return string
     */
    protected function redirectTo($request)
    {
        if (! $request->expectsJson()) {
            return route('login');
        }
    }
}

现在,因为没有任何requestJson(没有Accept头)。它将重定向我的路径('login')。同样的循环从再次登录开始,并在登录中保持循环。所以我只想知道我错过了什么??一些基本的php东西?或者是拉雷维尔少了什么。需要帮助请帮忙

如果您尝试在同一路线上同时使用
auth
guest
中间件,您将得到一个循环

您误解了
Authenticate
中间件中的代码的作用。
重定向到
仅在用户未登录时才起作用。该函数的目的是防止API调用重定向;API用户只会得到一个JSON响应,表明他们未经授权