Skip to content

Commit

Permalink
Merge pull request #11 from dikopylov/by-parent-scope
Browse files Browse the repository at this point in the history
add by parent
  • Loading branch information
efureev authored Oct 15, 2021
2 parents 4ecb960 + fe6663f commit ead51ef
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,22 @@ public function byLevel(?int $level): self
return $this;
}

/**
* @param int|string|Model|null $parent
*
* @return $this
*/
public function byParent(int|string|Model|null $parent): self
{
if ($parent !== null) {
$key = $parent instanceof Model ? $parent->getKey() : $parent;

$this->treeCondition()->where($this->model->parentAttribute()->name(), $key);
}

return $this;
}

/**
* Get wrapped column names
*
Expand Down

0 comments on commit ead51ef

Please sign in to comment.