Keep Track of Model Inventory with Laravel Stock

Laravel Stock is a package by Gijs Jorissen for keeping track of inventory counts on models:

Keep stock for Eloquent models. This package will track stock mutations for your models. You can increase, decrease, clear, and set stock. It’s also possible to check if a model is in stock (on a certain date/time).

For example, let’s say you have a Book model with which you need to keep track of stock:

use Appstract\Stock\HasStock; class Book extends Model
{ use HasStock;
}

When a customer places an order for a book, you can change the stock counts:

$book->increaseStock(10);
$book->decreaseStock(10); // Change stock positively or negatively with one method
$book->mutateStock(10);
$book->mutateStock(-10);

Next, in your UI you could check to see if a product is in stock:

$book->inStock();
// See if you have at least 10 of the same book in stock
$book->inStock(10);

Finally, you can clear stock out:

$book->clearStock(); // Clear stock and then set a new value
$book->clearStock(10);

You can learn more about this package, get full installation instructions, and view the source code on GitHub at appstract/laravel-stock.

Filed in: News / packages

Related posts

Tagged : /