0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Laravelでrequest->input()を使う時

Last updated at Posted at 2020-02-28

Requestからデータを得る時

// 推奨
$data = $request->input('data');

// 非推奨
$data = $request->input();
if($data['data']){
  // code...
}

request->input()ドキュメント)を用いる際、上の記述のやり方を用いると良い。
理由は、input()の引数を指定してあげることで、値が代入されていない場合、nullが返されるから。
下の記述だと、dataの値がnullだった場合、undefined variableとなってしまう。

0
0
2

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?