Skip to content

Instantly share code, notes, and snippets.

@jinoantony
Created June 18, 2018 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jinoantony/8d9dfaae199242fbccdd99f65110cfa7 to your computer and use it in GitHub Desktop.
Save jinoantony/8d9dfaae199242fbccdd99f65110cfa7 to your computer and use it in GitHub Desktop.
RedirectIfAuthenticated Middleware
<?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
* @param string $redirectTo
* @return mixed
*/
public function handle($request, Closure $next, $guard = null, $redirectTo = '/home')
{
if (Auth::guard($guard)->check()) {
return redirect($redirectTo);
}
return $next($request);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment