Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Generate Laravel Paginator Secure (HTTPS) Links

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?

like image 741
Waleed Ahmad Avatar asked Mar 01 '15 18:03

Waleed Ahmad


2 Answers

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');
like image 73
RDelorier Avatar answered Sep 28 '22 08:09

RDelorier


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());
like image 26
Bogdan Avatar answered Sep 28 '22 07:09

Bogdan