Skip to content

Commit 01ec50d

Browse files
authored
Update EloquentDataTable.php
1 parent 469a4bc commit 01ec50d

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/EloquentDataTable.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,35 @@ protected function getPrimaryKeyName(): string
8181
/**
8282
* @inheritDoc
8383
*/
84-
protected function compileQuerySearch($query, string $column, string $keyword, string $boolean = 'or'): void
84+
protected function compileQuerySearch($query, string $column, string $keyword, string $boolean = 'or', bool $nested = false): void
8585
{
86+
if (substr_count($column, '.') > 1) {
87+
$parts = explode('.', $column);
88+
$firstRelation = array_shift($parts);
89+
$column = implode('.', $parts);
90+
91+
if ($this->isMorphRelation($firstRelation)) {
92+
$query->{$boolean.'WhereHasMorph'}(
93+
$firstRelation,
94+
'*',
95+
function (EloquentBuilder $query) use ($column, $keyword) {
96+
parent::compileQuerySearch($query, $column, $keyword, '');
97+
}
98+
);
99+
} else {
100+
$query->{$boolean.'WhereHas'}($firstRelation, function (EloquentBuilder $query) use ($column, $keyword) {
101+
self::compileQuerySearch($query, $column, $keyword, '', true);
102+
});
103+
}
104+
105+
return;
106+
}
107+
86108
$parts = explode('.', $column);
87109
$newColumn = array_pop($parts);
88110
$relation = implode('.', $parts);
89111

90-
if ($this->isNotEagerLoaded($relation)) {
112+
if (!$nested && $this->isNotEagerLoaded($relation)) {
91113
parent::compileQuerySearch($query, $column, $keyword, $boolean);
92114

93115
return;

0 commit comments

Comments
 (0)