Reputation: 683
I have a Laravel Request object (collection) and there is an array inside this (address array)
I want to add a item to this array.
I tried $request->address['state'] = 'test';
and following error occurred.
Indirect modification of overloaded property Illuminate\Http\Request::$address has no effect
I want to add a item like highlighted in this img
Upvotes: 0
Views: 2072
Reputation: 1260
The easiest way it to get the associative array from the request and play with it.
$myRequest = $request->all();
$myRequest['address'] = ['state' => 'test'];
otherwise, you have to modify the request object you need to add this code:
$request->merge([
'address' => $myRequest
]);
Doc: https://laravel.com/api/5.6/Illuminate/Http/Request.html#method_merge
Upvotes: 1