From e4d0a065e4f6ea61b01739beda11d820b958a1cd Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Mon, 7 Dec 2020 08:01:05 -0500 Subject: [PATCH] [doc] Added another relation example to Many-To-One (#93) This is documented in Many-To-Many already, but not here. --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 69ca799ac..7441dcff3 100644 --- a/README.md +++ b/README.md @@ -603,6 +603,13 @@ PostFactory::new()->many(5)->create(); // create 5 Posts CommentFactory::new()->create(['post' => PostFactory::random()]); +// or create many, each with a different random Post +CommentFactory::new()->many(5) // create 5 comments + ->create(function() { // note the callback - this ensures that each of the 5 comments has a different Post + return ['post' => PostFactory::random()]; // each comment set to a random Post from those already in the database + }) +; + // Example 3: create a separate Post for each Comment CommentFactory::new()->many(5)->create([ // this attribute is an instance of PostFactory that is created separately for each Comment created