mercredi 21 février 2018

Putting array as arguments to Laravel's factory that is repeated

$categoryTitles = [
  'Games',
  'Running',
  'Hacking',
  'Walking',
];

$categoryDescriptions = [
  'this is nice',
  'kinda cool',
  'really good',
  'fine',
];

$categories = factory(App\Category::class, 4)->create([
  'title' => array_pop($categoryTitles),
  'description' => array_pop($categoryDescriptions),
]);

By looking at above code you probably will know what I am trying to do.

I wanna run 4 times factory with custom items defined in arrays.

But it doesn't work, because it takes last items from both arrays and is working on them 4 times. It doesn't take next and next until the array is empty.

I don't know exactly how to acomplish this. I think code explains what I wanna do.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire