From de0ab9354ef2d4052502fe8c098492a5d0efdbc8 Mon Sep 17 00:00:00 2001 From: Zach Garwood Date: Thu, 30 Jan 2025 14:45:13 -0600 Subject: [PATCH] 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`. --- src/Services/Listings/Columns/Relation.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Services/Listings/Columns/Relation.php b/src/Services/Listings/Columns/Relation.php index 9c6c05ec7..0fbabf766 100644 --- a/src/Services/Listings/Columns/Relation.php +++ b/src/Services/Listings/Columns/Relation.php @@ -5,6 +5,7 @@ use A17\Twill\Exceptions\ColumnMissingPropertyException; use A17\Twill\Models\Contracts\TwillModelContract; use A17\Twill\Services\Listings\TableColumn; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Support\Str; class Relation extends TableColumn @@ -44,9 +45,9 @@ protected function getRenderValue(TwillModelContract $model): string throw new ColumnMissingPropertyException('Relation column missing relation value: ' . $this->field); } - /** @var \Illuminate\Database\Eloquent\Collection $relation */ $model->loadMissing($this->relation); - $relation = collect($model->getRelation($this->relation)); + /** @var \Illuminate\Database\Eloquent\Collection $relation */ + $relation = Collection::wrap($model->getRelation($this->relation)); return $relation->pluck($this->field)->join(', '); }