/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function createAction() { // $projectData = Request::get('project'); $tags = array_pull($projectData, 'tags'); try { $projectData['creator_id'] = Auth::user()->id; $project = $this->dispatchFromArray(AddProjectCommand::class, $projectData); } catch (ValidationException $e) { return Redirect::route('projects.new')->withInput(Request::all())->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.projects.new.failure')))->withErrors($e->getMessageBag()); } // The project was added successfully, so now let's deal with the tags. $tags = preg_split('/ ?, ?/', $tags); // For every tag, do we need to create it? $projectTags = array_map(function ($taggable) use($project) { return Tag::firstOrCreate(['name' => $taggable])->id; }, $tags); $project->tags()->sync($projectTags); return Redirect::route('dashboard.projects.index')->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.projects.new.success'))); }
/** * Update an existing project. * * @param \Gitamin\Models\Project $project * * @return \Illuminate\Http\JsonResponse */ public function putProject(Request $request, Project $project) { try { $this->dispatch(new UpdateProjectCommand($project, $request->get('name'), $request->get('description'), $request->get('visibility_level'), $request->get('path'), $request->get('creator_id'), $request->get('owner_id'))); } catch (QueryException $e) { throw new BadRequestHttpException(); } if ($request->has('tags')) { $tags = preg_split('/ ?, ?/', $request->get('tags')); // For every tag, do we need to create it? $projectTags = array_map(function ($taggable) use($project) { return Tag::firstOrCreate(['name' => $taggable])->id; }, $tags); $project->tags()->sync($projectTags); } return $this->item($project); }
/** * Update an existing project. * * @param \Gitamin\Models\Project $project * * @return \Illuminate\Http\JsonResponse */ public function putProject(Project $project) { try { $this->dispatch(new UpdateProjectCommand($project, Binput::get('name'), Binput::get('description'), Binput::get('status'), Binput::get('slug'), Binput::get('order'), Binput::get('team_id'), (bool) Binput::get('enabled', true))); } catch (QueryException $e) { throw new BadRequestHttpException(); } if (Binput::has('tags')) { $tags = preg_split('/ ?, ?/', Binput::get('tags')); // For every tag, do we need to create it? $projectTags = array_map(function ($taggable) use($project) { return Tag::firstOrCreate(['name' => $taggable])->id; }, $tags); $project->tags()->sync($projectTags); } return $this->item($project); }