RedirectIfAuthenticated.php 811 Bytes
Newer Older
Taylor Otwell committed
1
<?php namespace App\Http\Middleware;
Taylor Otwell committed
2

Taylor Otwell committed
3
use Closure;
Taylor Otwell committed
4
use Illuminate\Contracts\Auth\Guard;
5
use Illuminate\Http\RedirectResponse;
Taylor Otwell committed
6

Taylor Otwell committed
7 8
class RedirectIfAuthenticated
{
Taylor Otwell committed
9

Taylor Otwell committed
10 11 12 13 14 15
    /**
     * The Guard implementation.
     *
     * @var Guard
     */
    protected $auth;
Taylor Otwell committed
16

Taylor Otwell committed
17 18 19 20 21 22 23 24 25 26
    /**
     * Create a new filter instance.
     *
     * @param  Guard  $auth
     * @return void
     */
    public function __construct(Guard $auth)
    {
        $this->auth = $auth;
    }
Taylor Otwell committed
27

Taylor Otwell committed
28 29 30 31 32 33 34 35 36 37 38 39
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if ($this->auth->check()) {
            return new RedirectResponse(url('/home'));
        }
Taylor Otwell committed
40

Taylor Otwell committed
41 42
        return $next($request);
    }
43
}