Created
February 5, 2021 15:18
-
-
Save reinink/af2154935f3ce99c53c8e7cbe450dcb6 to your computer and use it in GitHub Desktop.
Prevent relationship lazy-loading in Laravel
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 | |
namespace App; | |
use Exception; | |
use Illuminate\Database\Eloquent\Model as Eloquent; | |
class Model extends Eloquent | |
{ | |
public function getRelationshipFromMethod($name) | |
{ | |
$class = get_class($this); | |
throw new Exception("Lazy-loading relationships is not allowed ($class::$name)."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment