Created
October 7, 2018 20:11
-
-
Save mostafa6765/dfdaf64c8e89fa2569d0fd6f247319f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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