diff --git a/src/NavpiResource.php b/src/NavpiResource.php index ef354fe..9424b3c 100755 --- a/src/NavpiResource.php +++ b/src/NavpiResource.php @@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\HasOneThrough; use Illuminate\Database\Eloquent\Relations\MorphOne; +use \Illuminate\Database\Eloquent\Relations\Pivot; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Support\Collection; @@ -195,6 +196,15 @@ public function results() if (!is_null($resource->pivot) && in_array($pivot, array_keys($resource->pivot->attributesToArray()))) { $item[$name] = $resource->pivot->$pivot; } + if ($resource->pivot instanceof Pivot) { + $item[$name] = $resource->pivot->$pivot; + if (str_contains($pivot, '.')) { + $pivotName = explode('.', $pivot); + $pivotRelation = $pivotName[0]; + $pivotValue = $pivotName[1]; + $item[$name] = $resource->pivot->$pivotRelation->$pivotValue; + } + } continue; } if ($field->getType() == 'function') { @@ -251,6 +261,15 @@ public function results() if (!is_null($resource->pivot) && in_array($pivot, array_keys($resource->pivot->attributesToArray()))) { $item[$name] = $resource->pivot->$pivot; } + if ($resource->pivot instanceof Pivot) { + $item[$name] = $resource->pivot->$pivot; + if (str_contains($pivot, '.')) { + $pivotName = explode('.', $pivot); + $pivotRelation = $pivotName[0]; + $pivotValue = $pivotName[1]; + $item[$name] = $resource->pivot->$pivotRelation->$pivotValue; + } + } continue; } if ($field->getType() == 'function') {