Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kekekiw123's avatar

Laravel pagination returns links in http and not https

I am using the ->paginate(20); function on my query but the only problem is that it will return http and not https

Eg: "next_page_url":"http://www.mysite"

I have tried to force my app to use https by adding this in AppServiceProvider

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

So have can I force Laravel to return all links in https?

0 likes
12 replies
Snapey's avatar

The links should just mirror the request? Just check you are testing it correctly. If you load the page with https://.... then the pagination links should be the same?

1 like
Snapey's avatar

do you have a caching proxy or load balancer on the front?

ernest-okot's avatar
$users = User::paginate(20);
$users->setPath('');

For this, you'll get links like this

<a href="?page=1">1</a>
3 likes
sorcjc's avatar

@ernest-okot Thank you!

Now I am using ->setPath('/');.

And it works (the links are generated over https).

Edivandro's avatar

Add in AppServiceProvider.php

public function boot()
{
    $this->app['request']->server->set('HTTPS','on');
}
8 likes

Please or to participate in this conversation.