Skip to content

Instantly share code, notes, and snippets.

@kyleridolfo
Created September 30, 2015 19:53
Show Gist options
  • Save kyleridolfo/4e9c5f9bfa855c2bd63f to your computer and use it in GitHub Desktop.
Save kyleridolfo/4e9c5f9bfa855c2bd63f to your computer and use it in GitHub Desktop.
Secure Middleware for Laravel 5

Secure Middleware for Laravel 5

Installation

  • Add Secure.php to your app\Http\Middleware directory.
  • Add the secure middleware to your route.
  • run php artisan route:scan.

Notes

If you are using route annotations, don't forget to rescan your routes using the php artisan route:scan command.

<?php namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\Routing\Middleware;
class Secure implements Middleware {
public function handle($request, Closure $next)
{
if (!$request->secure() && \App::environment() === 'production') {
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