Filter component elements that aren't set
This commit is contained in:
@@ -26,14 +26,14 @@ class AddComponentCommandHandler
|
||||
*/
|
||||
public function handle(AddComponentCommand $command)
|
||||
{
|
||||
$component = Component::create([
|
||||
$component = Component::create(array_filter([
|
||||
'name' => $command->name,
|
||||
'description' => $command->description,
|
||||
'link' => $command->link,
|
||||
'status' => $command->status,
|
||||
'order' => $command->order,
|
||||
'group_id' => $command->group_id,
|
||||
]);
|
||||
]));
|
||||
|
||||
event(new ComponentWasAddedEvent($component));
|
||||
|
||||
|
||||
@@ -27,29 +27,17 @@ class UpdateComponentCommandHandler
|
||||
public function handle(UpdateComponentCommand $command)
|
||||
{
|
||||
$component = $command->component;
|
||||
$component->update($this->filterComponentData($command));
|
||||
|
||||
event(new ComponentWasUpdatedEvent($component));
|
||||
|
||||
return $component;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the command data.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Commands\Component\UpdateComponentCommand $command
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function filterComponentData($command)
|
||||
{
|
||||
return array_filter([
|
||||
$component->update(array_filter([
|
||||
'name' => $command->name,
|
||||
'description' => $command->description,
|
||||
'link' => $command->link,
|
||||
'status' => $command->status,
|
||||
'order' => $command->order,
|
||||
'group_id' => $command->group_id,
|
||||
]);
|
||||
]));
|
||||
|
||||
event(new ComponentWasUpdatedEvent($component));
|
||||
|
||||
return $component;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user