V
V
Vlad Avtomat2017-08-07 15:35:53
Laravel
Vlad Avtomat, 2017-08-07 15:35:53

How to correctly assign a value to a cell of a specific row?

$partnerProductsStatus = PartnerProductsStatus::all();
        $data = $request->except('_token');
        $partnerProductsStatus[0]->count = $data['many_status'];
        $partnerProductsStatus[0]->save();
        $partnerProductsStatus[1]->count = $data['average_status'];
        $partnerProductsStatus[1]->save();
        $partnerProductsStatus[2]->count = $data['few_status'];
        $partnerProductsStatus[2]->save();

I'm trying to assign by row ID, but here's the problem, I have two more rows (a total of five)
and when I save this whole thing - it only works fine the first time, the next time the ID shifts and the record goes to other cells.
Please tell me how to make assignment.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
ajaxtelamonid, 2017-08-07
@VladSavelev

[0], [1], [2] are not id, they are serial numbers in the array.
If you need to change specifically by id, then you need to do something like this:

PartnerProductsStatus::where("id", $id)->update(["count" => $value]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question