Skip to content

Commit a5c94f0

Browse files
✨ add support for MorphOne relationships
1 parent 60d60c2 commit a5c94f0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Traits/WithData.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Database\Eloquent\Builder;
66
use Illuminate\Database\Eloquent\Relations\BelongsTo;
77
use Illuminate\Database\Eloquent\Relations\HasOne;
8+
use Illuminate\Database\Eloquent\Relations\MorphOne;
89
use Rappasoft\LaravelLivewireTables\Views\Column;
910

1011
trait WithData
@@ -13,7 +14,7 @@ trait WithData
1314
public function getRows()
1415
{
1516
$this->baseQuery();
16-
17+
1718
return $this->executeQuery();
1819
}
1920

@@ -69,6 +70,7 @@ protected function joinRelation(Column $column): Builder
6970
$model = $lastQuery->getRelation($relationPart);
7071

7172
switch (true) {
73+
case $model instanceof MorphOne:
7274
case $model instanceof HasOne:
7375
$table = $model->getRelated()->getTable();
7476
$foreign = $model->getQualifiedForeignKeyName();
@@ -131,7 +133,7 @@ protected function getTableForColumn(Column $column): ?string
131133
foreach ($column->getRelations() as $relationPart) {
132134
$model = $lastQuery->getRelation($relationPart);
133135

134-
if ($model instanceof HasOne || $model instanceof BelongsTo) {
136+
if ($model instanceof HasOne || $model instanceof BelongsTo || $model instanceof MorphOne) {
135137
$table = $model->getRelated()->getTable();
136138
}
137139

0 commit comments

Comments
 (0)