在 laravel 中获取站点名称和协议

get site name along with protocol in laravel

如何使用 laravel 中使用的协议获取当前站点名称?

例如,假设用户请求了这个:

https://example.com/some/path

我想在控制器方法中获取 https://example.com

更新:

我使用 ngrok 服务来访问我的本地主机,作为它提供的 https 随机域,并以答案中建议的所有方式返回 main http://localhost

使用getSchemeAndHttpHost()方法:

request()->getSchemeAndHttpHost()

你可以简单地使用这个功能。

url('/');

使用这个:

request()->root()