Laravel | Don't load relations were mentioned in protected $with = []; #50964
Replies: 2 comments
-
Personally for me, this looks similar to a case when we use the morphWith method, but in reverse. framework/src/Illuminate/Database/Eloquent/Model.php Lines 74 to 79 in 81d8154 Example:
In this case, we specify that if it's a Post model, we don't need to load the 'user' relation. |
Beta Was this translation helpful? Give feedback.
-
$keyType property (defualt 'int') on the model might prevent loading the relations (even if fetched from DB). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a query:
A relation described in User model:
Code:
$users->first()->relation
could return different models as it’s Polymorphic Relationships, each model could have different Eager Loading by Default.How to avoid loading these relations were defined in each model in
protected $with = [];
?Beta Was this translation helpful? Give feedback.
All reactions