Created
December 29, 2015 18:11
-
-
Save waqasraza123/a6023e9c19b0ebceba2c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 namespace App\Http\Middleware; | |
use Closure; | |
use Illuminate\Contracts\Auth\Guard; | |
use Illuminate\Http\RedirectResponse; | |
class RedirectIfAuthenticated { | |
/** | |
* The Guard implementation. | |
* | |
* @var Guard | |
*/ | |
protected $auth; | |
/** | |
* Create a new filter instance. | |
* | |
* @param Guard $auth | |
* @return void | |
*/ | |
public function __construct(Guard $auth) | |
{ | |
$this->auth = $auth; | |
} | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @return mixed | |
*/ | |
public function handle($request, Closure $next) | |
{ | |
//if the user is logged in redirect to home | |
if ($this->auth->check()) | |
{ | |
return new RedirectResponse(url('/home')); | |
} | |
return $next($request); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment