Laravel 从路由生成安全的 https URL [英] Laravel generate secure https URL from route

查看:53
本文介绍了Laravel 从路由生成安全的 https URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑

我真的找不到从路由名称生成安全 URL 的方法.

I can't really find a way to generate a secure URL from route name.

要获取完整的 URL,我使用

To get a full URL, I use

echo route('my_route_name');

但是,如果我想要一个带有 https 的 URL,该怎么办?

But what to do, if I want a URL with https?

推荐答案

事实证明,laravel 并不关心 url 是否安全,因为它是根据当前 url 生成的.如果您在 https 页面上,route() 将返回安全 url.如果在 http,则 http:// url

Actually turns out, that laravel doesn't care if url is secure or not, because it generates based on the current url. If you're on https page, route() will return secure url. If on http, then http:// url

问题是,Laravel 没有检测到 https 已启用,这是由于服务器配置错误造成的.

The problem was, that Laravel didn't detect that https was enabled, which was due to faulty server configuration.

您可以通过调用 Request::isSecure();

这篇关于Laravel 从路由生成安全的 https URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆