laravel-stock
laravel-stock copied to clipboard
Option to directly save stock in stockable model table
The stock
method of the HasStock trait returns the current stock value if no date is given.
It gets the value by summing all the stock mutations the stockable model has.
It works without issues, however if there are thousands of stock mutations and it's required to have a page that shows hundreads of products and their stock, such SQL query might be quite expensive.
I think it would be useful to have an option to save the current stock after a stock mutation, so when calling the stock method without a date, it just returns the value, without the need to sum everything.
Would a PR for this feature be welcome?