in my Laravel app, the database has a column named "mavads" as :
{
"en": [
{
"need": "enn1",
"amount": "enm1"
},
{
"need": "enn2",
"amount": "enm2"
},
{
"need": "enn3",
"amount": "enm3"
},
],
"ru": [
{
"need": "run1",
"amount": "rum1"
},
{
"need": "run2",
"amount": "rum1"
},
]
}
This is the form that send data as PUT to the controller to update the database:
@foreach($food->mavads['en'] as $m)
<input type="text" class="input" name="enneed[]" value="{{ $m['need'] }}">
<input type="text" class="input" name="enamount[]" value="{{ $m['amount'] }}">
@endforeach
@foreach($food->mavads['ru'] as $m)
<input type="text" class="input" name="runeed[]" value="{{ $m['need'] }}">
<input type="text" class="input" name="ruamount[]" value="{{ $m['amount'] }}">
@endforeach
the Food Model:
protected $casts = [
'mavads' => 'array'
];
in Controller, I get $request and want to update each { "need": "run2","amount": "rum1"} of en or ru languages:
$enmavad = $request->only('enneed', 'enamount');
$rumavad = $request->only('runeed', 'ruamount');
$food->mavads = ["en" => $enmavad, "ru" => $rumavad];
but I get the error and no correct update
$enmavad