Skip to content

Commit edcbd28

Browse files
[6.x] Fix model MorphToMany relationships not being augmented. (#416)
* Fixed augmentation for MorphToMany relationships. * Fix style issue * Style fix attempt 2 * Fixed accidentally removing if statement. * Don't need these parentheses --------- Co-authored-by: Duncan McClean <duncan@duncanmcclean.com>
1 parent a3a9660 commit edcbd28

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Fieldtypes/BaseFieldtype.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Database\Eloquent\Model;
77
use Illuminate\Database\Eloquent\Relations\BelongsTo;
88
use Illuminate\Database\Eloquent\Relations\HasMany;
9+
use Illuminate\Database\Eloquent\Relations\MorphToMany;
910
use Illuminate\Support\Arr;
1011
use Illuminate\Support\Collection;
1112
use Statamic\CP\Column;
@@ -174,7 +175,7 @@ public function augment($values)
174175
{
175176
$resource = Runway::findResource($this->config('resource'));
176177

177-
if ($values instanceof HasMany) {
178+
if ($values instanceof HasMany || $values instanceof MorphToMany) {
178179
$results = $values
179180
->get()
180181
->map->toAugmentedArray()
@@ -242,7 +243,7 @@ public function shallowAugment($values)
242243
{
243244
$resource = Runway::findResource($this->config('resource'));
244245

245-
if ($values instanceof HasMany) {
246+
if ($values instanceof HasMany || $values instanceof MorphToMany) {
246247
$results = $values
247248
->get()
248249
->map->toShallowAugmentedArray()

0 commit comments

Comments
 (0)