As Laravel uses Symfony's ParameterBag to store the request's data it internally does this:
$p = new \Symfony\Component\HttpFoundation\ParameterBag(['foo' => 'bar', 'baz' => 'qux']);
$p->add(['baz' => 'xyz']);
dump(
$p->all()
);
Which prints out:
array:2 [
"foo" => "bar"
"baz" => "xyz"
]
Laravel's request exposes merge method that calls ParameterBag's add method internally. All is good until you manipulate one dimension data.
In your case, the solution could be like this:
$request = \Illuminate\Http\Request::create('/', 'POST',
[
'lines' => [
['price_ex_vat' => 'foo'],
['price_ex_vat' => 'bar'],
['price_ex_vat' => 'baz'],
],
]
);
$data = $request->input();
$data['lines'][1]['price_ex_vat'] = 'xyz'; // preg_replace or whatever you want.
dd(
$request->merge($data)->input();
);
Which prints accordingly:
array:1 [
"lines" => array:3 [
0 => array:1 [
"price_ex_vat" => "foo"
]
1 => array:1 [
"price_ex_vat" => "xyz"
]
2 => array:1 [
"price_ex_vat" => "baz"
]
]
]