Last active
April 10, 2017 14:17
-
-
Save tomfordweb/b3889ea3346ab1c0207c58723c99167b to your computer and use it in GitHub Desktop.
L5 Collection to CSV String for import
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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