我正在使用Laravel Framework 5.4.10,我正在使用常规身份验证
php artisan make:auth
Run Code Online (Sandbox Code Playgroud)
提供.我想保护整个应用程序,并在登录后将用户重定向到/ themes.
我有4个控制器:ForgotPasswordController.php,LoginController.php,RegisterController.php和ResetPasswordController.php.我已将此行编辑为最后三行:
protected $redirectTo = '/themes';
Run Code Online (Sandbox Code Playgroud)
这是我的routes/web.php中的第一行:
Auth::routes();
Run Code Online (Sandbox Code Playgroud)
我在Controller.php中添加了这个函数:
public function __construct()
{
$this->middleware('auth');
}
Run Code Online (Sandbox Code Playgroud)
我编辑了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);
}
Run Code Online (Sandbox Code Playgroud)
一切都很好,除非我点击登录按钮,我被重定向到"/",而不是"/ themes".如果我不需要在控制器中进行身份验证(Controller.php文件中没有__contruct函数),我会在登录时重定向.我究竟做错了什么?