Skip to content

Commit 74aca54

Browse files
zachgarwoodifox
authored andcommitted
Fix issue with Relation column
The Relation column does not properly display the value of fields on *-to-one related models. When `collect()` receives an individual object (such as an Eloquent model) it will convert it to an array. However, when `Collection::wrap()` receives an individual object it wraps it in a `Collection`.
1 parent 81091b0 commit 74aca54

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Services/Listings/Columns/Relation.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use A17\Twill\Exceptions\ColumnMissingPropertyException;
66
use A17\Twill\Models\Contracts\TwillModelContract;
77
use A17\Twill\Services\Listings\TableColumn;
8+
use Illuminate\Database\Eloquent\Collection;
89
use Illuminate\Support\Str;
910

1011
class Relation extends TableColumn
@@ -44,9 +45,9 @@ protected function getRenderValue(TwillModelContract $model): string
4445
throw new ColumnMissingPropertyException('Relation column missing relation value: ' . $this->field);
4546
}
4647

47-
/** @var \Illuminate\Database\Eloquent\Collection $relation */
4848
$model->loadMissing($this->relation);
49-
$relation = collect($model->getRelation($this->relation));
49+
/** @var \Illuminate\Database\Eloquent\Collection $relation */
50+
$relation = Collection::wrap($model->getRelation($this->relation));
5051

5152
return $relation->pluck($this->field)->join(', ');
5253
}

0 commit comments

Comments
 (0)