Created
August 16, 2017 18:39
-
-
Save cviebrock/dec80dedba34d112f9d537f5543c2cfc to your computer and use it in GitHub Desktop.
Prevent lazy-loading Eloquent relations
This file contains 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 | |
/** | |
* Apply this trait to your models, and lazy-loading relations will throw an exception. | |
*/ | |
trait DisableLazyLoading | |
{ | |
protected function getRelationshipFromMethod($method) | |
{ | |
$modelName = static::class; | |
throw new \LogicException( | |
"Attempting to lazy-load relation '$method' on model '$modelName'" | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment