php - Laravel: The data are not stored properly in the database column
Get the solution ↓↓↓I am having a hard time store the values of 'A' input values array to the database table. as shown in the screenshot. The expected output is that the 'A' values correspond properly to each mfo_id. If 'A' input type is blank then it will be null.
Controller Function(I used var_dump first to check the values before inserting)
public function storeipcrcsassocp(Request $request)
{
$store = [];
for($x=0; $x<count($request->mfo_id); $x++){
$store[] = [
"mfo_id" => $request->mfo_id[$x],
"function_name" => $request->function_name[$x],
"Q" => $request->Q[$x],
'average' => $request->A[$x],
'total_weighted_score' => $request->total_weighted_score[0],
];
}
var_dump($store);
Var dump output. The average value are the same.
Blade file. the input type are in the for loop
<input type="hidden" value="{{$row->function_name}}" name="function_name[]">
<input type="hidden" value="{{$row->id}}" name="mfo_id[]">
<input type="number" class="form-control form-control-sm" id="total-weighted-score" name="total_weighted_score[]" readonly>
<div class="form-label-group">
@if($row->function_name == 'Core Function')
<input type="number" class="form-control form-control-sm a-value-core" name="A[]" style="width: 50px" readonly>
@elseif($row->function_name == 'Support Function')
<input type="number" class="form-control form-control-sm a-value-support" name="A[]" style="width: 50px" readonly>
@endif
@if($row->function_name == 'Research and Extension Services')
<input type="number" class="form-control form-control-sm a-value-research" name="A[]" style="width: 50px" readonly>
@endif
</div>
Answer
Solution:
This is already resolved. Here are the keypoints on how I resolved it
- The for loop is correct
- There is a tag accidentally placed before the input type for A[]. After removing it the average values are now captured in var_dump($store) and dd($store) hence, I can now stored it in the database without any errors.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: cannot set properties of undefined (setting '_dt_cellindex')
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.