Laravel中,如果用戶已經(jīng)登陸,那么若其再打開登陸頁面,那么會(huì)默認(rèn)自動(dòng)跳轉(zhuǎn)至/home路徑。
要更改這個(gè)默認(rèn)設(shè)置,請打開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')一行換成我們想要用戶跳轉(zhuǎn)的地址即可:
return redirect()->route('my-route-name');
以上這篇Laravel 已登陸用戶再次查看登陸頁面的自動(dòng)跳轉(zhuǎn)設(shè)置方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:- laravel實(shí)現(xiàn)Auth認(rèn)證,登錄、注冊后的頁面回跳方法
- Laravel5.5 實(shí)現(xiàn)后臺(tái)管理登錄的方法(自定義用戶表登錄)
- Laravel實(shí)現(xiàn)用戶注冊和登錄