I think I have found the answer.
In my view policy, I retrieve some relationship to check the authorization.
What I would like now is to load this relationship only locally inside the policy.
Hello,
When I filter a collection of some model, I get a strange behavior.
The filtered collection seems to have eager loaded all relationships for each nested model. But I don't need to eager load anything. And before filtering, I don't have eager loaded any relationship.
Here is my filter code.
$courses->filter(function ($course) {
return auth()->user()->can('view', $course);
});
How is it possible ?
Thanks for your help to understand this.
V
@vincent15000 how else?
if you do auth()->user()->related->someattribute then the user model will be hydrated with the data
if you do $related = Related::where('user_id', auth()->id)->first(). then the related model is assigned to the variable and will be destroyed when the function ends.
Please or to participate in this conversation.