Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mostafa6765/dfdaf64c8e89fa2569d0fd6f247319f2 to your computer and use it in GitHub Desktop.
Save mostafa6765/dfdaf64c8e89fa2569d0fd6f247319f2 to your computer and use it in GitHub Desktop.
<?php
// 5.5 , 5.6
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)
{
switch ($guard) {
case 'admin':
if (Auth::guard($guard)->check()) {
return redirect()->route('dashboard');
}
break;
default:
if (Auth::guard($guard)->check()) {
return redirect('/home');
}
break;
}
return $next($request);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment