Adding a "lazyStore" in Eloquent Models #51945
Unanswered
florianJacques
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Recently, I needed to store the result of a complex request in my model using lazy loading.
I thought it might be interesting to integrate this natively into the models, so that it can be used directly via __get / getAttribute.
Here is my base code:
Example of usage:
Here I store in the key "products" the result of the request, and it is automatically cleared if one of the dependencies (here 'productIds') has undergone a change.
Happy reading!
Beta Was this translation helpful? Give feedback.
All reactions