Skip to content

Commit

Permalink
Merge pull request #53 from Geovanek/main
Browse files Browse the repository at this point in the history
Update Model.php for nested relations
  • Loading branch information
luanfreitasdev authored Aug 24, 2021
2 parents 6b8c61f + 69c4677 commit e12d746
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/Helpers/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,20 @@ private function makeRelation(): void
}

if ($this->query->getRelation($table)) {
foreach ($relation as $column) {
if (!Schema::hasColumn($this->query->getModel()->getTable(), $column)) {
return;
foreach ($relation as $nestedTable => $column) {
if (is_array($column)) {
if ($this->query->getRelation($table)->getRelation($nestedTable)){
foreach ($column as $nestedColumn) {
$this->query = $this->query->orWhereHas($table.'.'.$nestedTable, function (Builder $query) use ($nestedColumn) {
$query->where($nestedColumn, 'like', '%' . $this->search . '%');
});
}
}
} else {
$this->query = $this->query->orWhereHas($table, function (Builder $query) use ($column) {
$query->where($column, 'like', '%' . $this->search . '%');
});
}

$this->query = $this->query->orWhereHas($table, function (Builder $query) use ($column) {
$query->where($column, 'like', '%' . $this->search . '%');
});
}
}
}
Expand Down

0 comments on commit e12d746

Please sign in to comment.