Refactor validator stuff and fix variable names in views

This commit is contained in:
Graham Campbell
2015-08-03 22:32:36 +01:00
parent 5d958bac81
commit fcbbfdd84e
56 changed files with 514 additions and 766 deletions

View File

@@ -64,10 +64,6 @@ class ComponentController extends AbstractApiController
throw new BadRequestHttpException();
}
if (!$component->isValid()) {
throw new BadRequestHttpException();
}
if (Binput::has('tags')) {
// The component was added successfully, so now let's deal with the tags.
$tags = preg_split('/ ?, ?/', Binput::get('tags'));
@@ -94,9 +90,9 @@ class ComponentController extends AbstractApiController
*/
public function putComponent(Component $component)
{
$component->update(Binput::except('tags'));
if (!$component->isValid('updating')) {
try {
$component->update(Binput::except('tags'));
} catch (Exception $e) {
throw new BadRequestHttpException();
}
@@ -105,9 +101,7 @@ class ComponentController extends AbstractApiController
// For every tag, do we need to create it?
$componentTags = array_map(function ($taggable) use ($component) {
return Tag::firstOrCreate([
'name' => $taggable,
])->id;
return Tag::firstOrCreate(['name' => $taggable])->id;
}, $tags);
$component->tags()->sync($componentTags);