<?php

namespace App\Http\Middleware;

use Closure;

class HttpsProtocol {

    public function handle($request, Closure $next)
    {
        $whitelist = array(
            '127.0.0.1',
            '::1'
        );

        if (!$request->secure() && !in_array($_SERVER['REMOTE_ADDR'], $whitelist)) {
            return redirect()->secure($request->getRequestUri());
        }

        return $next($request);
    }
}
?>
