{"id":19700292,"url":"https://github.com/appstract/laravel-stock","last_synced_at":"2025-04-04T09:07:18.636Z","repository":{"id":45288580,"uuid":"247821830","full_name":"appstract/laravel-stock","owner":"appstract","description":"Keep stock for Eloquent models","archived":false,"fork":false,"pushed_at":"2022-07-23T18:00:38.000Z","size":49,"stargazers_count":290,"open_issues_count":6,"forks_count":38,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-03-28T08:05:14.814Z","etag":null,"topics":["laravel","stock"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/appstract.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"patreon":"appstract"}},"created_at":"2020-03-16T21:40:53.000Z","updated_at":"2025-02-13T06:29:57.000Z","dependencies_parsed_at":"2022-08-12T11:51:17.439Z","dependency_job_id":null,"html_url":"https://github.com/appstract/laravel-stock","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appstract%2Flaravel-stock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appstract%2Flaravel-stock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appstract%2Flaravel-stock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appstract%2Flaravel-stock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/appstract","download_url":"https://codeload.github.com/appstract/laravel-stock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247149500,"owners_count":20891954,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","stock"],"created_at":"2024-11-11T21:05:07.713Z","updated_at":"2025-04-04T09:07:18.616Z","avatar_url":"https://github.com/appstract.png","language":"PHP","funding_links":["https://patreon.com/appstract","https://www.paypal.me/appstract/10","https://www.patreon.com/appstract"],"categories":[],"sub_categories":[],"readme":"# Laravel Stock\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/appstract/laravel-stock.svg?style=flat-square)](https://packagist.org/packages/appstract/laravel-stock)\n[![Total Downloads](https://img.shields.io/packagist/dt/appstract/laravel-stock.svg?style=flat-square)](https://packagist.org/packages/appstract/laravel-stock)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n[![Build Status](https://img.shields.io/travis/appstract/laravel-stock/master.svg?style=flat-square)](https://travis-ci.org/appstract/laravel-stock)\n\nKeep 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).\n\n## Installation\n\nYou can install the package via composer:\n\n``` bash\ncomposer require appstract/laravel-stock\n```\n\nBy 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.\n\n## Usage\n\nAdding the `HasStock` trait will enable stock functionality on the Model.\n\n``` php\nuse Appstract\\Stock\\HasStock;\n\nclass Book extends Model\n{\n    use HasStock;\n}\n```\n\n### Basic mutations\n\n```php\n$book-\u003eincreaseStock(10);\n$book-\u003edecreaseStock(10);\n$book-\u003emutateStock(10);\n$book-\u003emutateStock(-10);\n```\n\n### Clearing stock\n\nIt's also possible to clear the stock and directly setting a new value.\n\n```php\n$book-\u003eclearStock();\n$book-\u003eclearStock(10);\n```\n\n### Setting stock\n\nIt is possible to set stock. This will create a new mutation with the difference between the old and new value.\n\n```php\n$book-\u003esetStock(10);\n```\n\n### Check if model is in stock\n\nIt's also possible to check if a product is in stock (with a minimal value).\n\n```php\n$book-\u003einStock();\n$book-\u003einStock(10);\n```\n\n### Current stock\n\nGet the current stock value (on a certain date).\n\n```php\n$book-\u003estock;\n$book-\u003estock(Carbon::now()-\u003esubDays(10));\n```\n\n### Stock arguments\n\nAdd a description and/or reference model to de StockMutation.\n\n```php\n$book-\u003eincreaseStock(10, [\n    'description' =\u003e 'This is a description',\n    'reference' =\u003e $otherModel,\n]);\n```\n\n### Query Scopes\n\nIt is also possible to query based on stock.\n\n```php\nBook::whereInStock()-\u003eget();\nBook::whereOutOfStock()-\u003eget();\n```\n\n## Testing\n\n``` bash\ncomposer test\n```\n\n## Contributing\n\nContributions are welcome, [thanks to y'all](https://github.com/appstract/laravel-stock/graphs/contributors) :)\n\n## About Appstract\n\nAppstract 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).\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fappstract%2Flaravel-stock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fappstract%2Flaravel-stock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fappstract%2Flaravel-stock/lists"}