PHPackages                             appstract/laravel-stock - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. appstract/laravel-stock

ActiveLibrary[Database &amp; ORM](/categories/database)

appstract/laravel-stock
=======================

Keep stock for Eloquent models

1.2.0(5y ago)29038.3k↓15.5%36[5 issues](https://github.com/appstract/laravel-stock/issues)[1 PRs](https://github.com/appstract/laravel-stock/pulls)MITPHPPHP ^7.2|^8.0

Since Mar 16Pushed 3y ago12 watchersCompare

[ Source](https://github.com/appstract/laravel-stock)[ Packagist](https://packagist.org/packages/appstract/laravel-stock)[ Docs](https://github.com/appstract/laravel-stock)[ Patreon](https://www.patreon.com/appstract)[ RSS](/packages/appstract-laravel-stock/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (6)Used By (0)

Laravel Stock
=============

[](#laravel-stock)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c0a020e7cb077252d060a3871ff2ff56f3b9742be5fc0e3b5e7920bb9a6daf8a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6170707374726163742f6c61726176656c2d73746f636b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/appstract/laravel-stock)[![Total Downloads](https://camo.githubusercontent.com/35812da92384cdf4aaaae2d3ded95e682656487dd6852606cecf300725fba672/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6170707374726163742f6c61726176656c2d73746f636b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/appstract/laravel-stock)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/9060164cb4017361888c0221405729089f99c95e22d8f169b1bf5305d85b65d0/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6170707374726163742f6c61726176656c2d73746f636b2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/appstract/laravel-stock)

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).

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require appstract/laravel-stock
```

By running `php artisan vendor:publish --provider="Appstract\Stock\StockServiceProvider"` in your project all files for this package will be published. Run `php artisan migrate` to migrate the table. There will now be a `stock_mutations` table in your database.

Usage
-----

[](#usage)

Adding the `HasStock` trait will enable stock functionality on the Model.

```
use Appstract\Stock\HasStock;

class Book extends Model
{
    use HasStock;
}
```

### Basic mutations

[](#basic-mutations)

```
$book->increaseStock(10);
$book->decreaseStock(10);
$book->mutateStock(10);
$book->mutateStock(-10);
```

### Clearing stock

[](#clearing-stock)

It's also possible to clear the stock and directly setting a new value.

```
$book->clearStock();
$book->clearStock(10);
```

### Setting stock

[](#setting-stock)

It is possible to set stock. This will create a new mutation with the difference between the old and new value.

```
$book->setStock(10);
```

### Check if model is in stock

[](#check-if-model-is-in-stock)

It's also possible to check if a product is in stock (with a minimal value).

```
$book->inStock();
$book->inStock(10);
```

### Current stock

[](#current-stock)

Get the current stock value (on a certain date).

```
$book->stock;
$book->stock(Carbon::now()->subDays(10));
```

### Stock arguments

[](#stock-arguments)

Add a description and/or reference model to de StockMutation.

```
$book->increaseStock(10, [
    'description' => 'This is a description',
    'reference' => $otherModel,
]);
```

### Query Scopes

[](#query-scopes)

It is also possible to query based on stock.

```
Book::whereInStock()->get();
Book::whereOutOfStock()->get();
```

Testing
-------

[](#testing)

```
composer test
```

Contributing
------------

[](#contributing)

Contributions are welcome, [thanks to y'all](https://github.com/appstract/laravel-stock/graphs/contributors) :)

About Appstract
---------------

[](#about-appstract)

Appstract is a small team from The Netherlands. We create (open source) tools for Web Developers and write about related subjects on [Medium](https://medium.com/appstract). You can [follow us on Twitter](https://twitter.com/appstractnl), [buy us a beer](https://www.paypal.me/appstract/10) or [support us on Patreon](https://www.patreon.com/appstract).

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity49

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 69.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~105 days

Total

5

Last Release

1831d ago

PHP version history (2 changes)1.0.0PHP ^7.2

1.2.0PHP ^7.2|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1470623?v=4)[Gijs Jorissen](/maintainers/gizburdt)[@gizburdt](https://github.com/gizburdt)

---

Top Contributors

[![gizburdt](https://avatars.githubusercontent.com/u/1470623?v=4)](https://github.com/gizburdt "gizburdt (25 commits)")[![kluverp](https://avatars.githubusercontent.com/u/14176515?v=4)](https://github.com/kluverp "kluverp (9 commits)")[![it-can](https://avatars.githubusercontent.com/u/644288?v=4)](https://github.com/it-can "it-can (2 commits)")

---

Tags

laravelstockappstractlaravel-stock

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/appstract-laravel-stock/health.svg)

```
[![Health](https://phpackages.com/badges/appstract-laravel-stock/health.svg)](https://phpackages.com/packages/appstract-laravel-stock)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90440.3M211](/packages/ramsey-uuid-doctrine)[appstract/laravel-options

Global options loaded from the database

730443.2k4](/packages/appstract-laravel-options)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
