Published under Laravel.
This trait provides a
temporary($relationship) method on your model for you to access relationships without adding them to the list of loaded relationships.
If the relationship is already loaded, it is returned directly. If the relationship is not loaded, it will be loaded, removed from the list of loaded relationships, and then returned.
The function is wrapped in Spatie's once package to add memoization. This allows the same temporary relationship to be called multiple times without multiple DB queries.
Use it within a model: