Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Add loadExists on Model and Eloquent Collection #37388

Merged
merged 2 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Illuminate/Database/Eloquent/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ public function loadAvg($relations, $column)
return $this->loadAggregate($relations, $column, 'avg');
}

/**
* Load a set of related existences onto the collection.
*
* @param array|string $relations
* @return $this
*/
public function loadExists($relations)
{
return $this->loadAggregate($relations, '*', 'exists');
}

/**
* Load a set of relationships onto the collection if they are not already eager loaded.
*
Expand Down
11 changes: 11 additions & 0 deletions src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,17 @@ public function loadAvg($relations, $column)
return $this->loadAggregate($relations, $column, 'avg');
}

/**
* Eager load related model existence values on the model.
*
* @param array|string $relations
* @return $this
*/
public function loadExists($relations)
{
return $this->loadAggregate($relations, '*', 'exists');
}

/**
* Eager load relationship column aggregation on the polymorphic relation of a model.
*
Expand Down