Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@azazqadir
Created September 14, 2018 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azazqadir/9e413dbfbb2e610fac66cea6f0cdbba8 to your computer and use it in GitHub Desktop.
Save azazqadir/9e413dbfbb2e610fac66cea6f0cdbba8 to your computer and use it in GitHub Desktop.
Enable SSL on Laravel Website and Enable Force HTTPS Redirect: https://www.cloudways.com/blog/how-to-setup-https-ssl-certificates-on-laravel-5/
namespace MyApp\Http\Middleware;
use Closure;
class HttpsProtocol {
public function handle($request, Closure $next)
{
if (!$request->secure() && env('APP_ENV') === 'prod') {
return redirect()->secure($request->getRequestUri());
}
return $next($request);
}
}
Then, apply this middleware to every request adding, setting the rule at Kernel.php file, like so:
protected $middleware = [
'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode',
'Illuminate\Cookie\Middleware\EncryptCookies',
'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse',
'Illuminate\Session\Middleware\StartSession',
'Illuminate\View\Middleware\ShareErrorsFromSession',
// appending custom middleware
'MyApp\Http\Middleware\HttpsProtocol'
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment