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')) {
//
}