我发现一个奇怪的问题只出现在制作中,而不是开发中。我的Laravel开发环境使用Homestead,生产是Forge,因此两个环境应该是相同的(除了.env值)。
我正在使用Laravel 5.2的身份验证并修改了RegistersUsers.php文件中的register方法,因为我不想在创建新用户后立即登录用户。相反,我重定向到一个新的路线,它只是显示静态视图,以便他们检查他们的电子邮件。只有在生产中,我才会在提交注册表单时看到以下错误 - 错误与重定向到/ verify有关。在dev中,它提交,在db中创建一个新用户,并按预期重定向到/ 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))