Home / Snippets / Force HTTPS for All Routes in Laravel 8
Force HTTPS for All Routes in Laravel 8 cover

Force HTTPS for All Routes in Laravel 8

395

3 years ago

0 comments

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

Alaz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

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

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this