Created
August 22, 2017 09:47
-
-
Save barryvdh/2578593e89d252737279f40b82be5b61 to your computer and use it in GitHub Desktop.
Force HTTPS Middleware
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; | |
class ForceHttps | |
{ | |
/** | |
* Force non-local requests to be HTTPS | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @param string|null $guard | |
* @return mixed | |
*/ | |
public function handle($request, Closure $next, $guard = null) | |
{ | |
if (!app()->isLocal() && !$request->isSecure()) { | |
return redirect()->secure($request->getRequestUri()); | |
} | |
return $next($request); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment