2018-05-20 16:19 阅读 40

第一次尝试后,Laravel 5.5重定向到登录页面

I have a login form in home, and I'm simply try to redirect the user to login page if the data is wrong. Here what I tried so far:

namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class RedirectIfAuthenticated
    public function handle($request, Closure $next, $guard = null)
        if (Auth::guard($guard)->check()) {
            return redirect('/');
        } else {
            return redirect('/login')->withInput();
        return $next($request);

It works only if the data is correct, otherwise I get ERR_TOO_MANY_REDIRECTS

The login page works.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享