Skip to content

Commit

Permalink
Merge pull request #29 from CoopBelvedere/dev_1.1.4
Browse files Browse the repository at this point in the history
Dev 1.1.4
  • Loading branch information
pascalboucher authored Oct 10, 2019
2 parents 58fae12 + 46f54e1 commit 05ea0d7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Latest Version on Packagist](https://img.shields.io/badge/packagist-v1.1.3-blue)](https://packagist.org/packages/coopbelvedere/laravel-form-maker)
[![Latest Version on Packagist](https://img.shields.io/badge/packagist-v1.1.4-blue)](https://packagist.org/packages/coopbelvedere/laravel-form-maker)
[![Build Status](https://travis-ci.org/CoopBelvedere/laravel-form-maker.svg?branch=master)](https://travis-ci.org/CoopBelvedere/laravel-form-maker)
[![StyleCI](https://github.styleci.io/repos/156127313/shield?branch=master)](https://github.styleci.io/repos/156127313)

Expand Down
19 changes: 7 additions & 12 deletions src/Repositories/NodeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,15 @@ public function all(Model $parent, ?string $type = null): Collection
/**
* Build a node model with label eager loaded.
*
* @param object|null $node
* @return Node|null
* @param object $node
* @return Node
*/
protected function buildNodeModel(?object $node): ?Node
protected function buildNodeModel(object $node): Node
{
if (is_null($node)) {
return null;
}

$label = $this->hydrateLabel($node);
$this->removeAttributes('label', $node);
$node = $this->hydrate($node);

if ($label) {
$node->setRelation('label', $label);
}
$node->setRelation('label', $label);

return $node;
}
Expand Down Expand Up @@ -133,7 +126,9 @@ public function find(Model $parent, $nodeKey, array $columns): ?Node
});
}

return $this->buildNodeModel($query->first());
$node = $query->first();

return is_null($node) ? null : $this->buildNodeModel($node);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Traits/Nodes/HasLabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ trait HasLabel
*/
public function addLabel(string $text): LabelerContract
{
if ($this->relationLoaded('label')) {
$this->unsetRelation('label');
}

$label = $this->nodeRepositoryProvider->getInstanceOf($this, 'label');

$label->withText($text)->save();
Expand Down

0 comments on commit 05ea0d7

Please sign in to comment.