Posts Learn Components Snippets Categories Tags Tools 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

219 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');
        }
    }
}

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️

Load comments for Force HTTPS for All Routes in Laravel 8

)