caryley / laravel-inventory
Laravel 模型的库存功能。
3.0.0
2023-01-25 18:12 UTC
Requires
- php: ^8.0|^8.1
- illuminate/support: ^9.0|^10.0
Requires (Dev)
- laravel/pint: ^1.4
- orchestra/testbench: ^7.0|^8.0
- pestphp/pest: ^1.22
README
The Laravel Inventory package helps track an inventory on any Laravel model.
该软件包提供以下功能
- 创建和设置新的库存
- 检索当前库存
- 管理库存数量
- 清除库存
- 确定模型是否在库存中。
- 确定模型是否有有效的库存
- 查询可库存模型的范围
安装
composer require caryley/laravel-inventory
使用以下命令发布迁移
php artisan vendor:publish --provider="Caryley\LaravelInventory\LaravelInventoryServiceProvider" --tag="migrations"
或者,可选地与 config
文件一起发布
php artisan vendor:publish --provider="Caryley\LaravelInventory\LaravelInventoryServiceProvider"
迁移 inventories
表
php artisan migrate
用法
将 HasInventory
特性添加到模型中。
... use Caryley\LaravelInventory\HasInventory; class Product extends Model { use HasInventory; ... }
hasValidInventory()
$product->hasValidInventory(); // Determine if the model has a valid inventory.
setInventory()
$product->setInventory(10); // $product->currentInventory()->quantity; (Will result in 10) | Not allowed to use negative numbers.
currentInventory()
$product->currentInventory() //Return inventory instance if one exists, if not it will return null.
addInventory()
$product->addInventory(); // Will increment inventory by 1. $product->addInventory(10); // Will increment inventory by 10.
incrementInventory()
$product->incrementInventory(10); // Will increment inventory by 10.
subtractInventory()
$product->subtractInventory(5); // Will subtract 5 from current inventory. $product->subtractInventory(-5); // Will subtract 5 from current inventory.
decrementInventory()
$product->decrementInventory(5); // Will subtract 5 from current inventory. $product->decrementInventory(-5); // Will subtract 5 from current inventory.
inInventory()
$product->inInventory(); // Will return a boolean if model inventory greater than 0. $product->inInventory(10); // Will return a boolean if model inventory greater than 10.
notInInventory()
$product->notInInventory(); // Determine if model inventory is less than 0.
clearInventory()
$product->clearInventory(); // Will clear all inventory for the model **Will delete all records, not only last record. $product->clearInventory(10); // Will clear the inventory for the model and will set new inventory of 10.
范围
InventoryIs()
- 该范围接受第一个参数为数量,第二个参数为运算符,第三个参数为模型ID或ID数组。
Product::InventoryIs(10)->get(); // Return all products with inventory of 10. Product::InventoryIs(10, '<=')->get(); // Return all products with inventory of 10 or less. Product::InventoryIs(10, '>=', [1,2,3])->get(); // Return all products with inventory of 10 or greater where product id is 1,2,3
InventoryIsNot()
- 该范围接受一个数量作为第一个参数,一个模型ID或ID数组作为第二个参数
Proudct::InventoryIsNot(10)->get(); // Return all products where inventory is not 10 Proudct::InventoryIsNot(10, [1,2,3])->get(); // Return all products where inventory is not 10 where product id is 1,2,3
变更日志
请查看 变更日志 了解最近的变化。
测试
composer test
贡献
请参阅 contributing.md 了解详细信息和工作列表。
安全
如果您发现任何与安全相关的问题,请通过作者的电子邮件而不是问题跟踪器来报告。
致谢
认可
Laravel-Inventory 从 spatie/laravel-model-status & appstract/laravel-stock 中汲取灵感(尽管它不依赖于它们中的任何一个)。
许可证
许可证。请参阅 许可证文件 了解更多信息。