gpt4 book ai didi

php - Laravel 分页返回 http 而不是 https 的链接

转载 作者:行者123 更新时间:2023-12-04 22:36:54 24 4
gpt4 key购买 nike

我正在使用 ->paginate(20);对我的查询起作用,但唯一的问题是它将返回 http 而不是 https

例如:"next_page_url":"http://www.mysite"
我试图通过在 AppServiceProvider 中添加它来强制我的应用使用 https

public function boot()
{
if (!\App::environment('local')) {
\URL::forceSchema('https');
}
}

那么我可以强制 Laravel 返回 https 中的所有链接吗?

最佳答案

我通过在分页器上设置路径让它工作:
Laravel 5.1+:

$results->paginate();
$results->setPath(''); // Will return ?page=2
// OR
$results->setPath(config('app.url')); // Will return website URL defined in .env file + ?page=
在 Laravel 5.1 之前:
$results->paginate();
$results->setBaseUrl('https://' . Request::getHttpHost() . '/' . Request::path());
我不相信它是最好的解决方案,但解决了我的问题。
Source 1
Source 2

关于php - Laravel 分页返回 http 而不是 https 的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40855766/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com