Posts Learn Components Snippets Categories Tags About
/

Force HTTPS for All Routes in Laravel 8

Learn how to force all routes to use HTTPS in Laravel 8 for a secure connection

Created on Aug 01, 2021

29 views

To ensure that your Laravel application has HTTPS, you can force the scheme by using "forceScheme()" method. To set it up, update the "boot" method of your "AppServiceProvider" file and then set the value to "https".

Force HTTPS in Laravel Code Example
<?php
  
namespace App\Providers;
  
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        if($this->app->environment('production')) {
            \URL::forceScheme('https');
        }
    }
}

Snippets by

PostSrc poster

PostSrc

Full stack developer mainly focusing on the front end side of the web. The main author of PostSrc and loves writing tutorial and guides online.

Load comments for Force HTTPS for All Routes in Laravel 8

new

PostSrc Code Components

Collection of Tailwind CSS components for everyone to use. Browse all of the components that's right for your project.

View Components

Other Code Snippets

More