0
0

More than 3 years have passed since last update.

LaravelのRequestクラス(入力の取得)

Last updated at Posted at 2020-03-06

Requestクラスの入力値の取得に関するメソッドのメモです。
基本的には公式リファレンスの内容を書いているだけですので、詳しくはそちらをご覧ください。
https://readouble.com/laravel/5.8/ja/requests.html

all()

すべての入力値を連想配列で取得できる。クエリストリング、アップロードファイルも取得する。


$input = $request->all();

input()

添付ファイルを除く、すべての入力値を連想配列で取得。

フォーム上のフィールド名を引数にとり、限定して取得できる。


$name = $request->input('name')

query()

入力をクエリストリングで取得。input()と同じく引数も渡せる。


$name = $request->query('name');

動的プロパティによる取得


$name = $request->name;

アップロードファイルも取得可能。

only(),except()

入力の一部取得。基本的にはall()を使っているため、アップロードファイルの取得もできる。


$input = $request->only('username', 'password');

$input = $request->except('credit_card');

file()

アップロードファイルを取得。
動的プロパティによる取得も可能。

ファイルの有無を判定するにはhasFile()を使う。

$file = $request->file('photo');

$file = $request->photo;

if ($request->hasFile('photo')) {
    //
}
0
0
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
0
0