Skip to main content

Laravel Force Https

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->app['request']->server->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' && !filter_var(request()->getHost(), FILTER_VALIDATE_IP)) {
                $this->app['request']->server->set('HTTPS', true);
        }
}

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