Created
September 4, 2015 00:26
-
-
Save sjardim/6d461b9b4f59cfbffdf5 to your computer and use it in GitHub Desktop.
Create post factory with relationships fields
This file contains 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
//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