LoginSignup
3
1

More than 1 year has passed since last update.

[docker + laravel(PHP)] GETパラメータが取得できない

Last updated at Posted at 2021-05-28

環境

laravel 8.x
php 8.0

問題

dockerのlaravel環境にて開発中にGETパラメータが取得できない問題に遭遇しました。以下を例に問題を示します。

<a href="{{ route('foo', ['bar' => 'baz']) }}">foo</a>

このように、barという名前でbazを渡すようにしました。しかし、実際にrequestの中身を確認すると、

dd($request)抜粋
  +request: Symfony\Component\HttpFoundation\InputBag {#51 ▼
    #parameters: []
  }

値が渡されていません!

原因

試しにMAMPで再現してみたところこちらでは正常に動作しました。ということはdockerに問題がありそうですね。

解決

nginxのdefault.confに以下の記述をlocation / {}内に追加してください。

try_files $uri $uri/ /index.php?$query_string;

コピペをお勧めします。私はindex.phpの後ろの?をつけ忘れていたため、長い間苦しみました......

追加したら、nginxの再起動を忘れずに!

これで元に戻りました!

  +request: Symfony\Component\HttpFoundation\InputBag {#51 ▼
    #parameters: array:1 [▼
      "foo" => "baz"
    ]
  }
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