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);
        }
}
```


Revision #2
Created 10 September 2023 12:45:42 by Admin
Updated 12 May 2025 09:10:12 by Editor