/** * 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); } } } } } }
/** * Execute the command. * * @param StartupRepository $repository * @return static */ public function handle(StartupRepository $repository) { switch ($this->action) { case 'approve': $repository->approveMemberRequest($this->user, $this->startup); Flash::message("Congratulations! {$this->user->profile->first_name} {$this->user->profile->last_name} has been accepted into your startup!"); break; case 'reject': $repository->rejectMemberRequest($this->user, $this->startup); Flash::message("{$this->user->profile->first_name} {$this->user->profile->last_name} has been rejected from your startup!"); break; } return $this->startup; }