Skip to content

Instantly share code, notes, and snippets.

@sjardim
Created September 4, 2015 00:26
Show Gist options
  • Save sjardim/6d461b9b4f59cfbffdf5 to your computer and use it in GitHub Desktop.
Save sjardim/6d461b9b4f59cfbffdf5 to your computer and use it in GitHub Desktop.
Create post factory with relationships fields
//create 15 posts with 3 comments and 3 tags each
$posts = factory('App\Post', 15)
->create()
->each(function($post) {
foreach(range(1,3) as $v){
$post->comments()->save(factory('App\Comment')->make());
$post->tags()->save(factory('App\Tag')->make());
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment