/** * Update an existing component. * * @param \CachetHQ\Cachet\Models\Component $component * * @return \Illuminate\Http\JsonResponse */ public function putComponent(Component $component) { try { dispatch(new UpdateComponentCommand($component, Binput::get('name'), Binput::get('description'), Binput::get('status'), Binput::get('link'), Binput::get('order'), Binput::get('group_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? $componentTags = array_map(function ($taggable) use($component) { return Tag::firstOrCreate(['name' => $taggable])->id; }, $tags); $component->tags()->sync($componentTags); } return $this->item($component); }
/** * Update an existing component. * * @param \CachetHQ\Cachet\Models\Component $component * * @return \Illuminate\Http\JsonResponse */ public function putComponent(Component $component) { try { $component->update(Binput::except('tags')); } catch (Exception $e) { throw new BadRequestHttpException(); } if (Binput::has('tags')) { $tags = preg_split('/ ?, ?/', Binput::get('tags')); // For every tag, do we need to create it? $componentTags = array_map(function ($taggable) use($component) { return Tag::firstOrCreate(['name' => $taggable])->id; }, $tags); $component->tags()->sync($componentTags); } return $this->item($component); }
/** * Creates a new component. * * @return \Illuminate\Http\RedirectResponse */ public function createComponentAction() { $componentData = Binput::get('component'); $tags = array_pull($componentData, 'tags'); try { $component = $this->dispatchFromArray(AddComponentCommand::class, $componentData); } catch (ValidationException $e) { return Redirect::route('dashboard.components.add')->withInput(Binput::all())->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.components.add.failure')))->withErrors($e->getMessageBag()); } // The component was added successfully, so now let's deal with the tags. $tags = preg_split('/ ?, ?/', $tags); // For every tag, do we need to create it? $componentTags = array_map(function ($taggable) use($component) { return Tag::firstOrCreate(['name' => $taggable])->id; }, $tags); $component->tags()->sync($componentTags); return Redirect::route('dashboard.components.add')->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.components.add.success'))); }
/** * Creates a new component. * * @return \Illuminate\Http\RedirectResponse */ public function createComponentAction() { $_component = Binput::get('component'); // We deal with tags separately. $tags = array_pull($_component, 'tags'); $component = Component::create($_component); if (!$component->isValid()) { segment_track('Dashboard', ['event' => 'Created Component', 'success' => false]); return Redirect::back()->withInput(Binput::all())->with('title', sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.components.add.failure')))->with('errors', $component->getErrors()); } segment_track('Dashboard', ['event' => 'Created Component', 'success' => true]); // The component was added successfully, so now let's deal with the tags. $tags = preg_split('/ ?, ?/', $tags); // For every tag, do we need to create it? $componentTags = array_map(function ($taggable) use($component) { return Tag::firstOrCreate(['name' => $taggable])->id; }, $tags); $component->tags()->sync($componentTags); $successMsg = sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.components.add.success')); return Redirect::back()->with('success', $successMsg); }