Update components through API

This commit is contained in:
Joseph Cohen
2015-02-22 22:22:01 -06:00
parent b0efc012c2
commit 683dccbfac
3 changed files with 56 additions and 0 deletions

View File

@@ -94,6 +94,33 @@ class ComponentController extends Controller
return $component;
}
/**
* Update an existing component.
*
* @param int $id
*
* @return \CachetHQ\Cachet\Models\Component
*/
public function putComponent($id)
{
$component = $this->component->update($id, Binput::except('tags'));
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 $component;
}
/**
* Delete an existing component.
*