# Laravel Force Https

```php
use Illuminate\Routing\UrlGenerator;

public function boot(UrlGenerator $url)
{
    public function register()
    {
      // force https
      if (config('app.env') !== 'local' && !filter_var(request()->getHost(), FILTER_VALIDATE_IP)) {
          $this->app['request']->server->set('HTTPS', true);
    }
}
```

need to put into AppServiceProvider

\# new version

```php  
public function register(): void  
{  
 $this-&gt;app\['request'\]-&gt;server-&gt;set('HTTPS', true);  
}

public function boot(): void  
{  
 if (strtolower(config('app.env')) == 'production') {  
 \\URL::forceScheme('https');  
 }  
}  
```  
   
\# old version

```php  
use Illuminate\\Routing\\UrlGenerator;

public function boot(UrlGenerator $url)  
{  
 if (config('app.env') !== 'local' &amp;&amp; !filter\_var(request()-&gt;getHost(), FILTER\_VALIDATE\_IP)) {  
 $this-&gt;app\['request'\]-&gt;server-&gt;set('HTTPS', true);  
 }  
}

public function register()  
{  
 if (config('app.env') !== 'local' &amp;&amp; !filter\_var(request()-&gt;getHost(), FILTER\_VALIDATE\_IP)) {  
 $this-&gt;app\['request'\]-&gt;server-&gt;set('HTTPS', true);  
 }  
}  
```