Skip to content

Instantly share code, notes, and snippets.

@tomfordweb
Last active April 10, 2017 14:17
Show Gist options
  • Save tomfordweb/b3889ea3346ab1c0207c58723c99167b to your computer and use it in GitHub Desktop.
Save tomfordweb/b3889ea3346ab1c0207c58723c99167b to your computer and use it in GitHub Desktop.
L5 Collection to CSV String for import
<?php
/**
* Generates a comma delimited by column with newline character for rows of models.
* If needed to be used on a actual model and not fake data, just pass the methods following the factory to the collection.
*/
$model = Model::class;
$quantity = 2;
$data = factory($model, $quantity)->make()->map(function($c) {
return $c->name . ',' . $c->email; //etc
})->implode("\r\n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment