Skip to content

Commit

Permalink
Merge pull request #35 from wnateg/patch-1
Browse files Browse the repository at this point in the history
Added withTrashed
  • Loading branch information
staudenmeir authored Apr 12, 2019
2 parents c88aa3d + b270dd4 commit 8d84330
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Relations/BelongsToThrough.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,28 @@ public function getRelationQuery(Builder $query, Builder $parent, $columns = ['*
{
return $this->getRelationExistenceQuery($query, $parent, $columns);
}

/**
* Restore soft-deleted models.
*
* @param string ...$columns
* @return $this
*/
public function withTrashed(...$columns)
{
if (empty($columns)) {
$this->query->withTrashed();
return $this;
}
if (is_array($columns[0])) {
$columns = $columns[0];
}
$this->query->getQuery()->wheres = collect($this->query->getQuery()->wheres)
->reject(function ($where) use ($columns) {
return $where['type'] === 'Null' && in_array($where['column'], $columns);
})->values()->all();
return $this;
}

/**
* Get the foreign key for the first "through" parent model.
Expand Down

0 comments on commit 8d84330

Please sign in to comment.