Laravel中,如果用户已经登陆,那么若其再打开登陆页面,那么会默认自动跳转至/home
路径。
要更改这个默认设置,请打开app/Http/Middleware/RedirectIfAuthenticated.php
:
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class RedirectIfAuthenticated
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect('/home');
}
return $next($request);
}
}
将其中的redirect('/home')
一行换成我们想要用户跳转的地址即可:
return redirect()->route('my-route-name');