0

我发现了一个奇怪的问题,它只出现在生产中,而不是开发中。我的 Laravel 开发环境使用 Homestead,生产环境是 Forge,所以两个环境应该是相同的(除了 .env 值)。

我正在使用 Laravel 5.2 的身份验证并修改了 RegistersUsers.php 文件中的注册方法,因为我不想在创建新用户后立即登录用户。相反,我重定向到一条新路线,该路线仅显示一个静态视图,供他们检查电子邮件。只有在生产中,我在提交注册表单时才会看到以下错误——该错误与重定向到 /verify 相关。在 dev 中,它提交,在数据库中创建一个新用户并按预期重定向到 /verify。

 public function register(Request $request)
    {
        $validator = $this->validator($request->all());

        if ($validator->fails()) {
            $this->throwValidationException(
                $request, $validator
            );
        }

//        Auth::guard($this->getGuard())->login($this->create($request->all()));
        $this->create($request->all());

        return redirect('/verify');
//        return redirect($this->redirectPath());
    }

此重定向路由如下,并仅显示一些静态 HTML:

Route::get('/verify', function () {return view('verify');});

出于某种奇怪的原因,当我在生产环境中提交注册表单时,会返回以下错误(以及一些堆栈跟踪消息):

2016-02-23 11:23:08] production.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Type error: Argument 1 passed to Illuminate\Auth\SessionGuard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, null given, called in /home/forge/mysite.com/bootstrap/cache/compiled.php on line 2542 in /home/forge/mysite.com/bootstrap/cache/compiled.php:628 Stack trace:
#0 /home/forge/mysite.com/bootstrap/cache/compiled.php(2542): Illuminate\Auth\SessionGuard->login(NULL)
#1 [internal function]: App\Http\Controllers\Auth\AuthController->register(Object(Illuminate\Http\Request))
#2 /home/forge/mysite.com/bootstrap/cache/compiled.php(9224): call_user_func_array(Array, Array)
#3 /home/forge/mysite.com/bootstrap/cache/compiled.php(9286): Illuminate\Routing\Controller->callAction('register', Array)
#4 /home/forge/mysite.com/bootstrap/cache/compiled.php(9266): Illuminate\Routing\ControllerDispatcher->call(Object(App\Http\Controllers\Auth\AuthController), Object(Illuminate\Routing\Route), 'register')
#5 [internal function]: Illuminate\Routing\ControllerDispatcher->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#6 /home/forge/mysite.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(52): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#7 /home/forge/mysite.com/app/Http/Middleware/RedirectIfAuthenticated.php(24): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#8 [internal function]: App\Http\Middleware\RedirectIfAuthenticated->handle(Object(Illuminate\Http\Request), Object(Closure))
#9 /home/forge/mysite.com/bootstrap/cache/compiled.php(9753): call_user_func_array(Array, Array)
#10 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#11 /home/forge/mysite.com/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#12 [internal function]: Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#13 /home/forge/mysite.com/bootstrap/cache/compiled.php(9743): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#14 /home/forge/mysite.com/bootstrap/cache/compiled.php(9267): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#15 /home/forge/mysite.com/bootstrap/cache/compiled.php(9254): Illuminate\Routing\ControllerDispatcher->callWithinStack(Object(App\Http\Controllers\Auth\AuthController), Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'register')

在上游游泳和跟踪此堆栈跟踪方面,我不是专家,因此我将不胜感激有关如何调试此生产错误的任何指示。似乎从堆栈跟踪 #8 开始,正在调用 RedirectIfAuthenticated 中间件,我不确定这是否有必要,因为我没有尝试登录用户。

#8 [internal function]: App\Http\Middleware\RedirectIfAuthenticated->handle(Object(Illuminate\Http\Request), Object(Closure))
4

0 回答 0