我正在使用Laravel Framework 5.4.10,同时正在使用常规认证。
php artisan make:auth
我希望保护整个应用程序,并在登录后将用户重定向到/themes。
我有4个控制器:ForgotPasswordController.php,LoginController.php,RegisterController.php和ResetPasswordController.php。我已经编辑了最后三个控制器中的这一行:
protected $redirectTo = '/themes';
这是我的routes/web.php文件中的第一行:
Auth::routes();
我已经在我的Controller.php中添加了这个函数:
public function __construct()
{
$this->middleware('auth');
}
我已经编辑了app/Http/Middleware/RedirectIfAuthenticated.php文件,使得handle函数变成了如下:
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect('/themes');
}
return $next($request);
}
除了当我点击登录按钮时,我被重定向到“ / ”而不是“ /themes”之外,一切都好。如果在控制器中不需要身份验证(Controller.php文件中没有__contruct函数),则登录时可以正确重定向。我做错了什么?