How to force Laravel to return SSL connection calls ?

 


It has been a pretty long day as I was struggling to get a Laravel application to return SSL or HTTPS connections. I was put in this situation because the SysOp team of my company placed the laravel app behind a loadbalancer accepting SSL connections but converting these connection to HTTP.

It seems trivial but it did mess with the laravel application that relies on the incoming protocol to define login/logout url pages for instances

After messing up and discovering TrustProxies I found an easy solution with

Here is my solution , open the file app/Providers/AppServiceProvider.php

And add the following line URL::forceScheme('https');

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\URL;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
      URL::forceScheme('https');
    }
}

Comments

Popular posts from this blog

How to fix pgDump dbeaver ?

Best PHP comment DockBlock !