Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/appstract/laravel-stock
Keep stock for Eloquent models
https://github.com/appstract/laravel-stock
laravel stock
Last synced: 3 days ago
JSON representation
Keep stock for Eloquent models
- Host: GitHub
- URL: https://github.com/appstract/laravel-stock
- Owner: appstract
- License: mit
- Created: 2020-03-16T21:40:53.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-07-23T18:00:38.000Z (over 2 years ago)
- Last Synced: 2024-12-18T13:02:36.233Z (10 days ago)
- Topics: laravel, stock
- Language: PHP
- Size: 47.9 KB
- Stars: 290
- Watchers: 13
- Forks: 38
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# Laravel Stock
[![Latest Version on Packagist](https://img.shields.io/packagist/v/appstract/laravel-stock.svg?style=flat-square)](https://packagist.org/packages/appstract/laravel-stock)
[![Total Downloads](https://img.shields.io/packagist/dt/appstract/laravel-stock.svg?style=flat-square)](https://packagist.org/packages/appstract/laravel-stock)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Build Status](https://img.shields.io/travis/appstract/laravel-stock/master.svg?style=flat-square)](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
You can install the package via composer:
``` bash
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
Adding the `HasStock` trait will enable stock functionality on the Model.
``` php
use Appstract\Stock\HasStock;class Book extends Model
{
use HasStock;
}
```### Basic mutations
```php
$book->increaseStock(10);
$book->decreaseStock(10);
$book->mutateStock(10);
$book->mutateStock(-10);
```### Clearing stock
It's also possible to clear the stock and directly setting a new value.
```php
$book->clearStock();
$book->clearStock(10);
```### Setting stock
It is possible to set stock. This will create a new mutation with the difference between the old and new value.
```php
$book->setStock(10);
```### Check if model is in stock
It's also possible to check if a product is in stock (with a minimal value).
```php
$book->inStock();
$book->inStock(10);
```### Current stock
Get the current stock value (on a certain date).
```php
$book->stock;
$book->stock(Carbon::now()->subDays(10));
```### Stock arguments
Add a description and/or reference model to de StockMutation.
```php
$book->increaseStock(10, [
'description' => 'This is a description',
'reference' => $otherModel,
]);
```### Query Scopes
It is also possible to query based on stock.
```php
Book::whereInStock()->get();
Book::whereOutOfStock()->get();
```## Testing
``` bash
composer test
```## Contributing
Contributions are welcome, [thanks to y'all](https://github.com/appstract/laravel-stock/graphs/contributors) :)
## 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
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.