@@ 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. |
@@ 63-91 (lines=29) @@ | ||
60 | * |
|
61 | * @return \Illuminate\Http\Response |
|
62 | */ |
|
63 | public function createAction() |
|
64 | { |
|
65 | // |
|
66 | $projectData = Binput::get('project'); |
|
67 | $tags = array_pull($projectData, 'tags'); |
|
68 | ||
69 | try { |
|
70 | $projectData['creator_id'] = Auth::user()->id; |
|
71 | $project = $this->dispatchFromArray(AddProjectCommand::class, $projectData); |
|
72 | } catch (ValidationException $e) { |
|
73 | return Redirect::route('projects.new') |
|
74 | ->withInput(Binput::all()) |
|
75 | ->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.projects.new.failure'))) |
|
76 | ->withErrors($e->getMessageBag()); |
|
77 | } |
|
78 | ||
79 | // The project was added successfully, so now let's deal with the tags. |
|
80 | $tags = preg_split('/ ?, ?/', $tags); |
|
81 | ||
82 | // For every tag, do we need to create it? |
|
83 | $projectTags = array_map(function ($taggable) use ($project) { |
|
84 | return Tag::firstOrCreate(['name' => $taggable])->id; |
|
85 | }, $tags); |
|
86 | ||
87 | $project->tags()->sync($projectTags); |
|
88 | ||
89 | return Redirect::route('dashboard.projects.index') |
|
90 | ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.projects.new.success'))); |
|
91 | } |
|
92 | ||
93 | /** |
|
94 | * Display the specified resource. |