jeudi 16 novembre 2017

Updating rows in laravel mysql database

think for the most this is a very basic question, but I didn't find a solution in the last hours and i'm pretty much a beginner in laravel and php.

I've set up a Database and want to update the column 'status' for each row in my UsersController:

I startet with this:

      User::where('id', '=', 1)->update(['status' => $status]);

This is working, but I need some loop to change all the rows, something like this:

1. foreach $id from the table
2. run some code to change individual $status variable
3. set individual $status value in the 'status' column in each row: 
   User::where('id', '=', $id)->update(['status' => $status])
4. end foreach

So for me its unclear how to go through the table via the foreach. Then save the calculated status from my code to each individual id?

Would appreciate if anyone can help.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2yNsuDn
via IFTTT

Aucun commentaire:

Enregistrer un commentaire