在laravel 5.1中,我覆盖了postRegister,然后将其重定向到路径并且运行良好,但在Laravel 5.2中,我编写了相同的代码,但它没有工作。这里有一些我的代码
public function postRegister(Request $request)
{
$validator = $this->validator($request->all());
if ($validator->fails()) {
$this->throwValidationException(
$request, $validator
);
}
$this->create($request->all());
return redirect('login');
}
这个我想在用户注册后重定向到页面登录。
我遇到了这样的问题:
SessionGuard.php第411行中的ErrorException:参数1传递给 Illuminate \ Auth \ SessionGuard :: login()必须实现接口 Illuminate \ Contracts \ Auth \ Authenticatable,null
注意:我使用了laravel默认scafold
提前致谢
答案 0 :(得分:0)
您的路由是否在web
中间件内? Laravel 5.2有一个名为中间件组的新功能。为了使用会话,您的路由应该在web
中间件内。如果您检查Kernel.php
,您将清楚了解web
中间件组中的中间件
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
],
答案 1 :(得分:0)
postRegister()
不再是要覆盖的方法。请改用:
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()));
return redirect(route('route.after.register'));
}
别忘了导入Auth Facade:
use Illuminate\Support\Facades\Auth;