Php 使用中间件和身份验证的多步骤注册表单导致无限循环

Php 使用中间件和身份验证的多步骤注册表单导致无限循环,php,laravel,laravel-5,Php,Laravel,Laravel 5,我正在尝试编写一个多步骤注册表单,其中第一个表单注册用户,下面的表单填写用户详细信息(单独的页面)。我的目标是允许用户(由于错误或故意)在注册第一个表单后退出,允许他们稍后登录并将其设置在停止的位置 我添加了一个数据库表“register_steps”来确定用户完成了哪个页面,然后我尝试将此数据拉入中间件并适当重定向 看起来我在Auth的重定向到和我的寄存器的重定向中间件之间遇到了一个无限循环冲突 中间件 路线 内核 最后,我将额外的表单分离到另一个控制器中,而不是RegisterControl

我正在尝试编写一个多步骤注册表单,其中第一个表单注册用户,下面的表单填写用户详细信息(单独的页面)。我的目标是允许用户(由于错误或故意)在注册第一个表单后退出,允许他们稍后登录并将其设置在停止的位置

我添加了一个数据库表“register_steps”来确定用户完成了哪个页面,然后我尝试将此数据拉入中间件并适当重定向

看起来我在Auth的重定向到和我的寄存器的重定向中间件之间遇到了一个无限循环冲突

中间件 路线 内核
最后,我将额外的表单分离到另一个控制器中,而不是RegisterController中,这样它就不会重定向,然后在我的OP中使用中间件检查db以查看表单是否已完成,如果没有,则重定向到未完成的表单

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;

class CompleteRegistration
{
    /**
     * Redirect user if profile is not complete
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if(Auth::user()){
            $step = Auth::user()->registration_steps;
            switch ($step) {
                case 1:
                    return redirect('/register/profile');
                    break;
                case 2:
                    return redirect('/register/photo');
                    break;
            }
        }
        return $next($request);
    }
}
// Authentication Routes...
Route::get('login', 'Auth\LoginController@showLoginForm')->name('login');
Route::post('login', 'Auth\LoginController@login');
Route::post('logout', 'Auth\LoginController@logout')->name('logout');

// Registration Routes...
Route::get('register', 'Auth\RegisterController@showRegistrationBasic')->name('register.basic');
Route::post('register', 'Auth\RegisterController@registerBasic');
Route::get('register/profile', 'Auth\RegisterController@showRegistrationProfile');
Route::post('register/profile', 'Auth\RegisterController@showRegistrationProfile');
Route::get('register/photo', 'Auth\RegisterController@showRegistrationPhoto');
Route::post('register/photo', 'Auth\RegisterController@showRegistrationPhoto');

// Password Reset Routes...
Route::get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm')->name('password.request');
Route::post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail')->name('password.email');
Route::get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm')->name('password.reset');
Route::post('password/reset', 'Auth\ResetPasswordController@reset');

// Website Pages
Route::get('/', 'WelcomeController@index')->middleware('guest');
Route::get('/browse', 'ProfileController@show')->middleware('auth', 'register');
Route::get('/profile', 'ProfileController@index')->middleware('auth', 'register');
Route::get('/profile/edit', 'ProfileController@edit')->middleware('auth', 'register');
protected $routeMiddleware = [
    'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
    'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
    'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
    'can' => \Illuminate\Auth\Middleware\Authorize::class,
    'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
    'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
    'register' => \App\Http\Middleware\CompleteRegistration::class
];