Skip to content

Instantly share code, notes, and snippets.

@bmadigan
Created August 4, 2017 21:39
Show Gist options
  • Save bmadigan/fcb758b139caac14033daf052713df90 to your computer and use it in GitHub Desktop.
Save bmadigan/fcb758b139caac14033daf052713df90 to your computer and use it in GitHub Desktop.
Laravel - An array to a collection with a loop
// Setup some developer accounts to test with
$developers = [
['name' => 'Tony Richards', 'email' => '[email protected]', 'password' => 'secret'],
['name' => 'Brad Madigan', 'email' => '[email protected]', 'password' => 'secret']
];
collect($developers)->each(function($dev) {
factory(\App\Models\User::class)->create([
'name' => $dev['name'],
'email' => $dev['email'],
'password' => bcrypt($dev['password']),
]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment