Skip to content

Instantly share code, notes, and snippets.

@waqasraza123
Created December 29, 2015 18:11
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 waqasraza123/a6023e9c19b0ebceba2c to your computer and use it in GitHub Desktop.
Save waqasraza123/a6023e9c19b0ebceba2c to your computer and use it in GitHub Desktop.
<?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