Force https (Laravel)

Provider (AppServiceProvider)

use Illuminate\Support\Facades\App;

    public function boot()
    {
        $env = App::environment();
        if($env == 'local' || $env == 'test'){
            define('USE_HTTPS', false);
        }else{
            define('USE_HTTPS', true);
        }

        if(USE_HTTPS == true){
            \URL::forceScheme('https');
            $base_url = secure_url('/');
        }else{
            $base_url = url('/');
        }

        define('BASE_URL', $base_url . '/');
        define('ASSETS_FRONT', $base_url . '/assets/front/');
        define('ASSETS_ADMIN', $base_url . '/assets/admin/');
    }

HTML:

    <script>
    var base_url = '{{BASE_URL}}';

    $(document).ready(function() {
      $.ajaxSetup({
        headers: {
          'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
        }
      });

      @if(USE_HTTPS == true)
      if (location.protocol != 'https:') {
        location.href = 'https:' + window.location.href.substring(window.location.protocol.length);
      }
      @endif
    });
    </script>