I'm developing an app using Laravel 4.2 over HTTPS with secure routes and redirects. I'm using Paginator to paginate results, but the links rendered in the view points to the http pages, how can we force Paginator to generate https links?
I had this issue today and found this global solution.
In your AppServiceProvider::boot method you can add the following to force https on pagination links
$this->app['request']->server->set('HTTPS','on');
If your current page is served over HTTPS, then the pagination URLs generated should use that schema.
However if you're using a proxy that does not pass the correct headers, the Request
class responsible for determining if the connection is secure, might not report it as such. To determine if the request is detected as secure use Request::secure()
. If that returns false
, try using Laravel Trusted Proxies.
If that does not work you can force the pagination URLs with setBaseUrl
as follows:
$results->paginate();
$results->setBaseUrl('https://' . Request::getHttpHost() . '/' . Request::path());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With