/** * Execute the command. * * @param StartupRepository $repository * @return static */ public function handle(StartupRepository $repository) { $slugify = Slugify::create(); $startup = Startup::create(['user_id' => $this->user->id, 'name' => $this->startup->name, 'description' => $this->startup->description, 'url' => $slugify->slugify($this->startup->name), 'stage_id' => $this->startup->stage_id, 'video' => $this->startup->video, 'published' => true]); $repository->save($startup); if (isset($this->startup->tags)) { $repository->updateTags($startup, $this->startup->tags); } if (isset($this->startup->needs)) { $repository->updateNeeds($startup, $this->startup->needs); } if (isset($this->startup->image)) { $repository->updateImage($startup, $this->startup->image); } return $startup; }
/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker\Factory::create(); $slugify = Slugify::create(); $users = User::all(); $tags = Tag::all(); $skills = Skill::all(); foreach ($users as $user) { foreach (range(1, rand(2, 3)) as $i) { $name = $faker->name; $startup = Startup::create(['name' => $name, 'description' => $faker->text, 'url' => $slugify->slugify($name), 'user_id' => $user->id, 'published' => true]); $this->repository->save($startup); $startupTags = []; foreach (range(1, rand(2, 4)) as $i) { $id = rand(1, count($tags) - 1); $startupTags[] = $id; } $needs = []; $commitments = ['full-time', 'part-time']; foreach (range(1, rand(2, 3)) as $i) { $roleId = rand(1, count($skills) - 1); $needTags = []; foreach (range(1, rand(2, 3)) as $i) { $id = rand(1, count($tags) - 1); $needTags[] = $id; } $needs[] = array('role' => $roleId, 'quantity' => rand(1, 10), 'skills' => implode(',', $needTags), 'commitment' => $commitments[rand(0, 1)], 'desc' => $faker->text); $this->repository->updateNeeds($startup, $needs); } $startup->tags()->attach($startupTags); foreach (range(1, rand(2, 3)) as $i) { $id = rand(1, count($users) - 1); if ($startup->owner->id !== $id) { $this->repository->addMemberRequest($users[$id], $startup, false); if (rand(0, 1)) { $this->repository->approveMemberRequest($users[$id], $startup, false); } } } } } }