Skip to content
Advertisement

Laravel update all users age by x

I want to update all users in my database with an age value which I get from my request. How do I manage this? I somehow need the current value in the db and multiple it.

JavaScript

Advertisement

Answer

Let’s assume that the name of the field in your $request is multiple, you can iterate over your customer records and update each of them, applying your multiple value to their age:

JavaScript

If you want to use the QueryBuilder rather than Eloquent, then you can do the following:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement