• Stars
    star
    287
  • Rank 144,232 (Top 3 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 4 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Keep stock for Eloquent models

Laravel Stock

Latest Version on Packagist Total Downloads Software License Build Status

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:

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.

use Appstract\Stock\HasStock;

class Book extends Model
{
    use HasStock;
}

Basic mutations

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

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

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

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

Current stock

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

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

Stock arguments

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

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

Query Scopes

It is also possible to query based on stock.

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

Testing

composer test

Contributing

Contributions are welcome, thanks to y'all :)

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. You can follow us on Twitter, buy us a beer or support us on Patreon.

License

The MIT License (MIT). Please see License File for more information.

More Repositories

1

laravel-opcache

Laravel Package for OPcache
PHP
1,327
star
2

laravel-blade-directives

A collection of nice Laravel Blade directives
PHP
858
star
3

laravel-options

Global key-value store in the database
PHP
722
star
4

laravel-multisite

Multiple sites on one codebase
PHP
216
star
5

laravel-bootstrap-components

Bootstrap components as Laravel components
HTML
192
star
6

laravel-meta

Metadata for Eloquent model
PHP
129
star
7

laravel-tracer

Shows the path of each blade file loaded in a template
PHP
98
star
8

nova-horizon

Horizon statistics in Nova
Vue
79
star
9

lush-http

Smart Http Client for PHP
PHP
63
star
10

dd.js

Laravel dd() in JS
JavaScript
53
star
11

laravel-elixir-env

Use .env variables in Javascript with Laravel Elixir
JavaScript
39
star
12

laravel-response-macros

Extra response macro's for Laravel
PHP
33
star
13

laravel-referer-redirector

Manage redirects based on referers
PHP
32
star
14

nova-opcache

OPcache Tool for Laravel Nova
Vue
19
star
15

php-hostsfile

Read & Write HostsFile Entries with PHP
PHP
13
star
16

laravel-artisan-scan

[WIP] Scan for multiple improvement points
PHP
11
star
17

laravel-crawl-render

Pre-render Javascript sites for web crawlers
PHP
11
star
18

laravel-dusk-safari

Run Dusk tests in Safari
PHP
11
star
19

skeleton-php

Skeleton for PHP packages
PHP
11
star
20

vue-validate

[DEPRECATED] Input validation for Vue
JavaScript
10
star
21

laravel-moneybird

Laravel package for Moneybird
PHP
9
star
22

laravel-dusk-opera

Run Dusk tests in Opera
PHP
8
star
23

nova-signature-field

Signature Pad as a Nova Field
Vue
7
star
24

pakketpartner-php-client

PHP Client for the Pakketpartner API
PHP
7
star
25

laravel-pakketpartner

Wrapper for the Pakketpartner PHP Client
PHP
4
star
26

laravel-bol-retailer

Wrapper package for Bol.com Retailer API
PHP
2
star
27

laravel-twikey

PHP
2
star