Help us understand the problem. What is going on with this article?

merge: Requestデータを追加・上書き for Laravel

Requestクラスに値をセットするにはmergeです。

NG_ダメです
//これやりがちですができません。
$request->input('name') = 'ichiro';
追加・上書き
use lluminate\Http\Request;

$request = new Request;
$request->merge(['name' => 'ichiro']);
//名前があればチーム名を新たに追加
if ($request->has('name')) {
    //追加
    $request->merge(['team' => 'Mariners']);
}
echo $request->input('name'); //ichiro
//上書き
$request->merge(['name' => 'taro']);
echo $request->input('name'); //taro

LGTMよろしくお願いします。
励みになります!

Fell
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away