laravel-stock icon indicating copy to clipboard operation
laravel-stock copied to clipboard

Option to directly save stock in stockable model table

Open hfoletto opened this issue 3 years ago • 0 comments

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?

hfoletto avatar Nov 16 '21 18:11 hfoletto