Ben's developer blog
Welcome to my blog. I'm a developer and I created this blog as a place to share things I learn that I think will be useful to other developers.

Force all URLs generated by Laravel to use https

Posted on Saturday 12th January 2019

When developing a Laravel project you might find yourself using Laravel to auto generate URLs to routes. Laravel won't automatically generate URLs using https and when using forms within your website if you are accessing the website with https and the form is using http you'll run into browser issues and warnings.

To force Laravel to generate all URLs using https you can implement the small code snippet below inside the AppServiceProvider class.

URL::forceScheme('https');

You will also need to include the following in the top of the class:

use Illuminate\Support\Facades\URL;

The AppServiceProvider class is located in app/providers.