/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $startup = $request->segment(2); $startup = Startup::where('url', '=', $startup)->firstOrFail(); if (false == Auth::user() or $startup->owner->id != Auth::user()->id) { return Redirect::route('startups.show', ['startup' => $startup->url]); } return $next($request); }
/** * Execute the command. * * @param StartupRepository $repository * @return Startup */ public function handle(StartupRepository $repository) { $startup = Startup::updateStartup($this->startup, $this->data); $repository->save($startup); if (isset($this->data['tags'])) { $repository->updateTags($startup, $this->data['tags']); } if (isset($this->data['needs'])) { $repository->updateNeeds($startup, $this->data['needs']); } if (isset($this->data['image'])) { $repository->updateImage($startup, $this->data['image']); } return $startup; }
/** * 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); } } } } } }
/** * @param null $tag * @param null $needs * @param null $orderBy * @param int $perPage * @return \Illuminate\Pagination\Paginator */ public function allActive($tag = null, $needs = null, $orderBy = null, $perPage = 12) { $results = Startup::where('published', '=', true)->with('owner')->with('needs')->with('tags')->with('ratings'); if ($tag) { $results->join('needs', 'startups.id', '=', 'needs.startup_id')->join('startup_tag', 'startup_tag.startup_id', '=', 'startups.id')->join('need_tag', 'need_tag.need_id', '=', 'needs.id')->join('tags', function ($join) { $join->on('need_tag.tag_id', '=', 'tags.id')->orOn('startup_tag.tag_id', '=', 'tags.id'); })->where('tags.name', '=', $tag)->select('startups.*'); } if ($needs) { $results->whereHas('needs', function ($q) use($needs) { $q->where('needs.skill_id', '=', $needs); }); } if ($orderBy) { $results->orderBy($orderBy); } else { $results->orderBy('id', 'DESC'); } $paginatedResults = $results->paginate($perPage); if ($needs or $tag) { $paginatedResults->appends(['needs' => $needs, 'tag' => $tag]); } return $paginatedResults; }
/** * @param UpdateStartup $request * @param $startup * @return mixed */ public function update(UpdateStartup $request, $startup) { $startup = Startup::where('url', '=', $startup)->firstOrFail(); $this->dispatch(new UpdateStartupCommand($startup, $request->all())); Flash::message('Startup updated successfully!'); return Redirect::action('StartupController@show', $startup->url); }
/** * Remove the specified resource from storage. * DELETE /membership/{id} * * @param int $startup * @return Response */ public function destroy($startup) { $startup = Startup::where('url', '=', $startup)->firstOrFail(); $this->dispatch(new CancelMembership(Auth::user(), $startup)); return Redirect::route('startups.show', ['url' => $startup->url]); }
/** * Invite the user to a startup */ public function invite() { $userTo = User::findOrFail(Input::get('user_id')); $startup = Startup::findOrFail(Input::get('startup_id')); $userFrom = Auth::user(); ThreadRepository::notification('startup.join.invite.talent', $userTo, array('startup' => $startup, 'fromUser' => $userFrom)); Flash::message('You have successfully invited ' . $userTo->profile->first_name); return Redirect::intended('/users/' . $userTo->id); }