<?php

namespace App\Http\Middleware;

use \App\User;
use Illuminate\Support\Facades\Auth;

class RequireHTTPS
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, $next)
    {
        if(isset($_SERVER['HTTPS'])) {
            if ($_SERVER['HTTPS'] == "on") {
                // OK
                return $next($request);
            } 
        }
        
        else return redirect()->secure($request->getRequestUri());
    }

}