LoginSignup
3
1

More than 1 year has passed since last update.

Laravel ペジネーションのリンクをHttps対応にする

Last updated at Posted at 2022-03-27

発生した問題

一覧表示画面のペジネーションリンクから2ページ目の一覧表示画面へアクセスしようとしたところ、「アクセス時間が長すぎます。」と出て、一向に画面遷移しない状態が続きました。

デベロッパーツールからペジネーションのリンクを確認すると、httpsではなくhttpでアクセスしようとしてることがわかりました。
どうやらペジネーションのリンクは、1ページ目はhttpsに対応してるが、2ページ目以降はhttpで通信されてしまうらしい。。。

ということで、以下のように修正してhttpsでアクセスできるようにしてあげます!

AppServiceProvider.phpを修正

/app/Providers/AppServiceProvider.phpに以下のコードを追加。

public function boot(UrlGenerator $url)
{
    $url->forceScheme('https');

       // 以下を追記
    // ペジネーションリンクをhttps対応(.env APP_ENV=localでない場合https化)
    if (!$this->app->environment('local')) {
        $this->app['request']->server->set('HTTPS', 'on');
    }
}

最後に

これでペジネーションのリンクから2ページ目以降にアクセスできるようになりました!
独自ドメインをhttps化していたので、ペジネーションリンクもhttps対応にする必要があったようです。

参考記事

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1