Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to update a single value with laravel

Hello i want to update a single value on another table using laravel. This is the code i have done until now but doesnt seem to work:

        $amount = Product::findorFail($request->products[$i]);
        $total_value = $request->amount[$i] + $amount->amount;
        $amount->update(['amount', $total_value]);
        dd($total_value);

with dd i see that the result is correct but the update function is not, the query im trying to make is

update table set amount=x where id=y

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You have multiple choices. The shortes are:

$amount->update(['amount'=> $amount->amount + request->amount[$i]]);

or

Product::findorFail($request->products[$i])->increment('amount', $request->amount[$i]);

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading