Created
November 25, 2015 15:18
-
-
Save YOzaz/1e682f5cdaeeb7d3861d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Lazy loads relationship if required | |
* | |
* @param \Eloquent $model | |
* @param string $relationship | |
* | |
* @return object | |
*/ | |
function load( &$model, $relationship ) | |
{ | |
if ( !isset( $model->{$relationship} ) ) | |
{ | |
$model->load( $relationship ); | |
} | |
return $model->{$relationship}; | |
} | |
// usage example | |
$comments = load( $post, 'comments' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment