Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 升级到Laravel 5.2-索引重定向循环验证中间件_Php_Laravel_Authentication_Routing_Laravel 5 - Fatal编程技术网

Php 升级到Laravel 5.2-索引重定向循环验证中间件

Php 升级到Laravel 5.2-索引重定向循环验证中间件,php,laravel,authentication,routing,laravel-5,Php,Laravel,Authentication,Routing,Laravel 5,我目前正在将我的一个项目从4.2升级到5.2 昨天我在5.1中一切正常,所以我开始升级5.2。 当然,我严格遵循了文档()中的所有步骤 我很快就能让一切正常工作,但我完全陷入了由验证中间件引起的重定向循环中 这是我缩小范围的方法 经过数小时的测试和搜索,我得到了一个非常小的设置,其中的错误仍然存在 routes.php(其他内容均已注释): 最后是Authenticate.php中间件(laravel 5.2中包含的基本中间件): 但我不明白为什么会这样! -我的索引路由不应该触发身份验证中间件

我目前正在将我的一个项目从4.2升级到5.2

昨天我在5.1中一切正常,所以我开始升级5.2。 当然,我严格遵循了文档()中的所有步骤

我很快就能让一切正常工作,但我完全陷入了由验证中间件引起的重定向循环中

这是我缩小范围的方法 经过数小时的测试和搜索,我得到了一个非常小的设置,其中的错误仍然存在

routes.php(其他内容均已注释):

最后是Authenticate.php中间件(laravel 5.2中包含的基本中间件):

但我不明白为什么会这样! -我的索引路由不应该触发身份验证中间件 -我的SessionController在其构造函数中不使用任何中间件

我在升级过程中错过了什么吗?除了routes.php控制器的构造函数中的声明之外,还有什么会导致中间件触发


任何帮助都将非常感谢=)

另一种方法是在内核的$middleware属性中放置一个中间件。这些是针对所有路由执行的中间件。从那里删除accessmiddleware,它将不会被应用,除非明确启用。哦,好吧,我不记得我的$middleware内容来自哪里(自从bug出现以来,进行了很多测试),但实际上我从laravel github恢复了kernel.php,现在它可以工作了!非常感谢!=)
<?php

/*
|--------------------------------------------------------------------------
| Routes non-ressources de l'application
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/

Route::get('/', ['as'=>'index', 'uses'=>'SessionsController@create']);
<?php

class SessionsController extends \BaseController
{
    /**
     * Show the form for creating a new resource.
     *
     * @return Response
     */
    public function create()
    {
    // dd('toto');
        if (Auth::check()) {
            return Redirect::to('/accueil');
        }
        return View::make('pages.login');
    }


    /**
     * Store a newly created resource in storage.
     *
     * @return Response
     */
    public function store()
    {
        if (Auth::attempt(Input::only('email', 'password'))) {
            return Redirect::to('/accueil');
        }
        Flash::error(Lang::get('global.login_error'));
        return Redirect::back()->withInput();
    }


    /**
     * Log the user out
     *
     * @return Response
     */
    public function destroy()
    {
        Session::flush();
        Auth::logout();
        return Redirect::to('login');
    }


}
/**
     * The application's global HTTP middleware stack.
     *
     * @var array
     */
    protected $middleware = [
        'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode',
        'Illuminate\Cookie\Middleware\EncryptCookies',
        'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse',
        'Illuminate\Session\Middleware\StartSession',
        'Illuminate\View\Middleware\ShareErrorsFromSession',
        'App\Http\Middleware\VerifyCsrfToken',
        'App\Http\Middleware\Authenticate',
        'App\Http\Middleware\RedirectIfAuthenticated',
        // 'App\Http\Middleware\AccessMiddleware',
    ];

    /**
     * The application's route middleware.
     *
     * @var array
     */
    protected $routeMiddleware = [
        'auth' => 'App\Http\Middleware\Authenticate',
        'auth.basic' => 'Illuminate\Auth\Middleware\AuthenticateWithBasicAuth',
        // 'auth.canaccess' =>'App\Http\Middleware\AccessMiddleware',
        'guest' => 'App\Http\Middleware\RedirectIfAuthenticated',
    ];
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class Authenticate
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @param  string|null  $guard
     * @return mixed
     */
    public function handle($request, Closure $next, $guard = null)
    {
        if (Auth::guard($guard)->guest()) {
            if ($request->ajax()) {
                return response('Unauthorized.', 401);
            } else {
                return redirect()->guest('/');
            }
        }
        return $next($request);
    }
}
return redirect()->guest('/');