Esempio n. 1
0
 /**
  * Update an existing component.
  *
  * @param \CachetHQ\Cachet\Models\Componet $component
  *
  * @return \CachetHQ\Cachet\Models\Component
  */
 public function putComponent(Component $component)
 {
     $component->update(Binput::except('tags'));
     if (!$component->isValid('updating')) {
         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);
 }
Esempio n. 2
0
 /**
  * Updates a component.
  *
  * @param \CachetHQ\Cachet\Models\Component $component
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function updateComponentAction(Component $component)
 {
     $_component = Binput::get('component');
     $tags = array_pull($_component, 'tags');
     $component->update($_component);
     if (!$component->isValid()) {
         return Redirect::back()->withInput(Binput::all())->with('title', sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.components.edit.failure')))->with('errors', $component->getErrors());
     }
     // 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.edit.success'));
     return Redirect::back()->with('success', $successMsg);
 }