Created
March 28, 2019 19:58
-
-
Save stevebauman/97a49f7dd728a69e8dc0942981caeb1f to your computer and use it in GitHub Desktop.
A Laravel HTTP middleware to force HTTPS requests. Doesn't run when running in local development or when running unit tests.
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 | |
| { | |
| /** | |
| * Handle an incoming request. | |
| * | |
| * @param \Illuminate\Http\Request $request | |
| * @param \Closure $next | |
| * | |
| * @return mixed | |
| */ | |
| public function handle($request, Closure $next) | |
| { | |
| // If the application is running in production and the request is | |
| // not secure, we'll redirect users to the secure URL. | |
| if ( | |
| ! app()->isLocal() && | |
| ! app()->runningUnitTests() && | |
| ! $request->isSecure() | |
| ) { | |
| return redirect()->secure($request->path()); | |
| } | |
| return $next($request); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment