protected function createEntity(array $data) { $entity = new Page($data); $group = GroupSynker::select($this->groups(), $data['group']); if (!$group) { throw new \Exception('Failed to bind group: no matched group found: ' . $this->groupData['title']); } $entity->group()->associate($group); return $entity; }
/** * Run the database seeds. * * @return void */ public function run() { $authors = Author::all(); $this->iterate(self::PAGES_TO_SEED / 2, self::PAGES_TO_SEED, function ($i) use($authors) { $author = $authors->random(); do { $author = $authors->random(); } while ($author->groups->isEmpty()); $faker = $this->faker(); $page = new Page(); $page->title = $faker->sentence(5); $page->annotation = Str::limit(join(' ', $faker->sentences(5)), 250); $page->link = $faker->slug(3); $page->size = $faker->numberBetween(0, 9999); $page->author()->associate($author); $page->group()->associate($author->groups->random()); $page->save(); }); }