diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index e23c1880e3bb..960ccdb7edb2 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -379,6 +379,21 @@ public function load($relations) return $this; } + /** + * Eager load relations on the model if they are not already eager loaded. + * + * @param array|string $relations + * @return $this + */ + public function loadIfNotLaded($relations) + { + $relations = is_string($relations) ? func_get_args() : $relations; + + return $this->load(array_filter($relations, function ($relation) { + return ! $this->relationLoaded($relation); + })); + } + /** * Increment a column's value by a given amount. *