Photo by Joanna Kosinska on Unsplash

How to resolve Mixed Content error in Laravel

theoneamin
May 25, 2021

Often when you deploy your Laravel application, you notice there is a mixed content warning saying that youwebsite.come was loaded over HTTPS but requested an insecure …

There are a few walkarounds you could use to get rid of this warning. The first thing you want to do is set your app URL in your environment to HTTPS. Also in config/app.php, set the URL fallback to HTTPS.

Then in your AppServiceProvider, replace your boot function with the following. Remember to import the UrlGenerator class.

public function boot(UrlGenerator $url){
if(env('APP_ENV') !== 'local'){
$url->forceScheme('https');
}
}

That is it. On your next deployment, your application content should be served over HTTPS.

Thanks for reading.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

theoneamin
theoneamin

No responses yet

Write a response