Skip to content

Commit

Permalink
Merge pull request #56 from yassipad/laravel-5.8
Browse files Browse the repository at this point in the history
Laravel 5.8 compatibility
  • Loading branch information
Yasser Lahbibi authored May 9, 2019
2 parents d7b185d + 370ae7e commit 01aaa97
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
"dependencies": {
"vue": "^2.5.0"
}
}
}
10 changes: 10 additions & 0 deletions src/NestedForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,14 @@ protected function isManyRelationship()
{
return isset($this->meta['has_many']) || isset($this->meta['morph_many']);
}

/**
* Checks whether the user is using Nova > 2.
*
* @return bool
*/
protected function isUsingNova2()
{
return Str::startsWith(Nova::version(), '2');
}
}
1 change: 0 additions & 1 deletion src/Traits/FillsSubAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ protected function fillAttributeFromRequest(NovaRequest $request, $requestAttrib
}

$this->removeCurrentAttribute($request, $attribute);

} else {
$model::saved(function ($model) use ($request, $requestAttribute, $attribute) {
$this->fillAttributeFromRequest($request, $requestAttribute, $model, $attribute);
Expand Down
14 changes: 7 additions & 7 deletions src/Traits/HasSubfields.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,10 @@ protected function filteredFields(string $filterKey)
{
return $this->resourceInstance->availableFields($this->request)->reject(function ($field) use ($filterKey) {
return $field instanceof ListableField ||
$field instanceof ResourceToolElement ||
$field->attribute === $this->resourceInstance::newModel()->getKeyName() ||
$field->attribute === 'ComputedField' ||
!$field->$filterKey ||
(isset($field->resourceName) && ($field->resourceName === $this->meta['viaResource']) && $this->setInverseRelationship($field->attribute)) ||
($this->request->getMethod() === 'GET' && ($field instanceof MorphTo || $field instanceof MorphToMany));
$field instanceof ResourceToolElement ||
$field->attribute === $this->resourceInstance::newModel()->getKeyName() ||
$field->attribute === 'ComputedField' ||
!$field->$filterKey || (isset($field->resourceName) && ($field->resourceName === $this->meta['viaResource']) && $this->setInverseRelationship($field->attribute)) || ($this->request->getMethod() === 'GET' && ($field instanceof MorphTo || $field instanceof MorphToMany));
});
}

Expand All @@ -80,7 +78,9 @@ public function setInverseRelationship(string $inverseRelationship)
{
$this->inverseRelationship = $inverseRelationship;

$this->inverseRelationshipKey = $this->resourceInstance::newModel()->{$inverseRelationship}()->getForeignKey();
$foreignKeyMethod = $this->isUsingNova2() ? 'getForeignKeyName' : 'getForeignKey';

$this->inverseRelationshipKey = $this->resourceInstance::newModel()->{$inverseRelationship}()->{$foreignKeyMethod}();

return $this;
}
Expand Down

0 comments on commit 01aaa97

Please sign in to comment.