Skip to content

Instantly share code, notes, and snippets.

@barryvdh
Created August 22, 2017 09:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save barryvdh/2578593e89d252737279f40b82be5b61 to your computer and use it in GitHub Desktop.
Save barryvdh/2578593e89d252737279f40b82be5b61 to your computer and use it in GitHub Desktop.
Force HTTPS Middleware
<?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