diff --git a/src/Illuminate/Database/Eloquent/Collection.php b/src/Illuminate/Database/Eloquent/Collection.php index 05c785eff15..e8435ce3dbc 100755 --- a/src/Illuminate/Database/Eloquent/Collection.php +++ b/src/Illuminate/Database/Eloquent/Collection.php @@ -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. * diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index bc212651496..6005ce5f3b3 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -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. *