EN ES
Home > Web development > Laravel Tutorials > Force URL::to() and url() Using Https Laravel 5.2

Force URL::to() and url() Using Https Laravel 5.2

Diego Cortés
Diego Cortés
September 2, 2016
Force URL::to() and url() Using Https Laravel 5.2

We will see how to force the routes created with the url() and URL::to() helpers to use HTTPS instead of HTTP in Laravel 5.2 without modifying all our views one by one, for this we will go to the file:

\App\Providers\AppServiceProvider.php

where within the boot() function we have to add the following code:

if (\App::environment('production')) {
    \URL::forceSchema('https');
}

In this case we are first checking if in our .env file we have set the environment as production, if this is the case it will force the use of HTTPS in the routes created with the url() and URL::to() helpers.

That's all, I hope it helps more than one

Tested in Laravel 5.1 and 5.2

Diego Cortés
Diego Cortés
Full Stack Developer, SEO Specialist with Expertise in Laravel & Vue.js and 3D Generalist

Categories

Page loaded in 31.92 ms