如果页面是通过https加载的,则Laravel使用url()或route()来提供https url


Laravel use url() or route() to serve https URLs if the page loaded via https

如果页面通过https加载,是否有办法覆盖所有route()url()以强制提供https URL?

我们目前正在使用cloudflare,它已经将http转换为https,但由于某种原因,当您访问例如时https://www.website.com/some-page,通过route()URL()生成的URL不会自动从http转换为https。有没有一种方法可以强制模式为https?

我使用了以下代码,它对我有效:

   if (!'App::environment('local')) {
              'URL::forceSchema('https');
         }

在Path:''app''Providers''AppServiceProvider.php引导函数中添加此代码

将APP_ENV=本地替换为根.ENV文件上的生产。