/** * 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); }