| @@ 195-221 (lines=27) @@ | ||
| 192 | * |
|
| 193 | * @return \Illuminate\Http\RedirectResponse |
|
| 194 | */ |
|
| 195 | public function createProjectAction() |
|
| 196 | { |
|
| 197 | $projectData = Binput::get('project'); |
|
| 198 | $tags = array_pull($projectData, 'tags'); |
|
| 199 | ||
| 200 | try { |
|
| 201 | $project = $this->dispatchFromArray(AddProjectCommand::class, $projectData); |
|
| 202 | } catch (ValidationException $e) { |
|
| 203 | return Redirect::route('dashboard.projects.add') |
|
| 204 | ->withInput(Binput::all()) |
|
| 205 | ->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.projects.add.failure'))) |
|
| 206 | ->withErrors($e->getMessageBag()); |
|
| 207 | } |
|
| 208 | ||
| 209 | // The project was added successfully, so now let's deal with the tags. |
|
| 210 | $tags = preg_split('/ ?, ?/', $tags); |
|
| 211 | ||
| 212 | // For every tag, do we need to create it? |
|
| 213 | $projectTags = array_map(function ($taggable) use ($project) { |
|
| 214 | return Tag::firstOrCreate(['name' => $taggable])->id; |
|
| 215 | }, $tags); |
|
| 216 | ||
| 217 | $project->tags()->sync($projectTags); |
|
| 218 | ||
| 219 | return Redirect::route('dashboard.projects.index') |
|
| 220 | ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.projects.add.success'))); |
|
| 221 | } |
|
| 222 | ||
| 223 | /** |
|
| 224 | * Deletes a given project. |
|
| @@ 57-85 (lines=29) @@ | ||
| 54 | * |
|
| 55 | * @return \Illuminate\Http\Response |
|
| 56 | */ |
|
| 57 | public function createAction() |
|
| 58 | { |
|
| 59 | // |
|
| 60 | $projectData = Binput::get('project'); |
|
| 61 | $tags = array_pull($projectData, 'tags'); |
|
| 62 | ||
| 63 | try { |
|
| 64 | $projectData['creator_id'] = Auth::user()->id; |
|
| 65 | $project = $this->dispatchFromArray(AddProjectCommand::class, $projectData); |
|
| 66 | } catch (ValidationException $e) { |
|
| 67 | return Redirect::route('projects.new') |
|
| 68 | ->withInput(Binput::all()) |
|
| 69 | ->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.projects.new.failure'))) |
|
| 70 | ->withErrors($e->getMessageBag()); |
|
| 71 | } |
|
| 72 | ||
| 73 | // The project was added successfully, so now let's deal with the tags. |
|
| 74 | $tags = preg_split('/ ?, ?/', $tags); |
|
| 75 | ||
| 76 | // For every tag, do we need to create it? |
|
| 77 | $projectTags = array_map(function ($taggable) use ($project) { |
|
| 78 | return Tag::firstOrCreate(['name' => $taggable])->id; |
|
| 79 | }, $tags); |
|
| 80 | ||
| 81 | $project->tags()->sync($projectTags); |
|
| 82 | ||
| 83 | return Redirect::route('dashboard.projects.index') |
|
| 84 | ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.projects.new.success'))); |
|
| 85 | } |
|
| 86 | ||
| 87 | /** |
|
| 88 | * Display the specified resource. |
|