1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【:: と ->、そして query() と input() の違いについて】

Posted at

忘れないようにメモ書き程度ですが、残しておきます!

「::」 と 「->」 の違い(メソッドの呼び出し方)

書き方 読み方 使う場面
:: スコープ解決演算子 クラスから直接(static)呼び出す時 CommentsService::postComments(...)
-> アロー演算子 インスタンス(オブジェクト)から呼び出す時 $this->commentsService->postComments(...)

補足:
・:: を使うときは、クラス内のメソッドや定数に static(静的)な定義が必要。

・-> は、newなどで生成されたオブジェクトに対して使う方法です。

query() と input() の違い(リクエストの取得方法)

メソッド 対象 使いどころ
query('キー') クエリパラメータ(URLの?以降) GETで渡されるURLパラメータを取得したい時 $request->query('threadId')
input('キー') フォーム・クエリ・JSONすべて POSTやPUTなど、すべての入力を取得したい時 $request->input('commentsContent')

補足:
・query() は URLの中のパラメータだけを対象にします。

・input() は POSTデータや JSONボディなども含む、より広い範囲のデータ取得です。

query() と input() の違い(リクエストの取得方法)

ざっくりまとめると…

・:: → クラスそのものから呼び出す(static)

・-> → オブジェクト(インスタンス)から呼び出す

・query() → URLパラメータ専用

・input() → POST/PUTやその他の全入力に対応

1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?