vendredi 13 décembre 2019

Laravel seeder use same value in loop

I need to add an extra uuid field to a table I'm using. So I created a seeder which is getting all the rows in this table and adding a generated uuid for each row.

$retailerBrands = App\RetailerBrand::all();

        $retailerBrands->map(function($retailerBrand){
            $uuid = Uuid::generate(4)->string;
            var_dump("Value of uuid generated ", $uuid);
            $retailerBrand->uuid = $uuid; 
            $retailerBrand->save();
        });

But all my rows always end up with the same uuid (the first one generated), even if when I dump my generated uuid I can see that it is different at each loop. It seems as i it was caching the value the first time and using it on all the other loops.

I guess I'm doing something stupid here but I can't find out what.

Any help will be useful.

Thank you.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire