I have 100 records in the database, each record has a value
field that is equal to 0
How can I use migration to change the value of the value field so that this value is in the reverse order? For example, like this: -1, -2, -3, -4 ...
I have 100 records in the database, each record has a value
field that is equal to 0
How can I use migration to change the value of the value field so that this value is in the reverse order? For example, like this: -1, -2, -3, -4 ...
Make a migration and set in the up method your query e.g like this ( untested ) :
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
foreach(YourModel::all() as $key => $value) {
$value->value = ++$key * (-1)
$value->save();
}
}