controlla_ccd / laravel-inventory
Laravel 的库存管理
dev-master
2023-08-04 18:24 UTC
Requires
- php: ^7.4|^8.0|^8.1
- illuminate/contracts: ^8.0|^9.0|^10.0
- illuminate/database: ^8.0|^9.0|^10.0
- spatie/laravel-package-tools: ^1.4.3
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/larastan: ^2.0
- orchestra/testbench: ^6.0|^7.0|^8.0
- phpunit/phpunit: ^9.3
- spatie/laravel-ray: ^1.9
- tightenco/duster: ^2.0
- vimeo/psalm: ^4.4
This package is auto-updated.
Last update: 2024-09-04 20:47:43 UTC
README
这里应该放置您的描述。请限制在一两段之内。考虑添加一个小示例。
支持我们
我们投入了大量资源来创建 一流的开放源代码包。您可以通过 购买我们的付费产品之一 来支持我们。
我们非常感谢您从家乡寄给我们明信片,并提及您正在使用我们哪个包。您可以在 我们的联系页面 上找到我们的地址。我们将在 我们的虚拟明信片墙上 发布收到的所有明信片。
安装
您可以通过 composer 安装此包
composer require controlla/laravel-inventory
您可以使用以下命令发布并运行迁移
php artisan vendor:publish --provider="Controlla\Inventory\InventoryServiceProvider" --tag="laravel-inventory-migrations"
php artisan migrate
您可以使用以下命令发布配置文件
php artisan vendor:publish --provider="Controlla\Inventory\InventoryServiceProvider" --tag="laravel-inventory-config"
这是已发布的配置文件的内容
return [
/*
|--------------------------------------------------------------------------
| Inventory Class
|--------------------------------------------------------------------------
/
/ The class of inventory model that holds all inventories. The model
/ must be or extend `Controlla\Inventory\Inventory::class`
/ for the inventory package to work properly.
/
*/
'inventory_model' => Controlla\Inventory\Inventory::class,
/*
|--------------------------------------------------------------------------
| Default field attribute
|--------------------------------------------------------------------------
/
/ The name of the column which holds the key for the relationship with the model related to the inventory.
/ You can change this value if you have set a different name in the migration for the inventories
/ table. You might decide to go with the SKU field instead of the ID field.
/
*/
'model_primary_field_attribute' => 'inventoriable_id',
/*
|--------------------------------------------------------------------------
| Allow no user
|--------------------------------------------------------------------------
|
| Allows inventory changes to occur without a user responsible.
|
*/
'allow_no_user' => false,
/*
|--------------------------------------------------------------------------
| Allow Duplicate Movements
|--------------------------------------------------------------------------
|
| Allows inventory stock movements to have the same before and after quantity.
|
*/
'allow_duplicate_movements' => true,
/*
|--------------------------------------------------------------------------
| Rollback Cost
|--------------------------------------------------------------------------
|
| For example, if the movement's cost that is being rolled
| back is 500, the rolled back movement will be -500.
|
*/
'rollback_cost' => true,
/*
|--------------------------------------------------------------------------
| Skus Enabled
|--------------------------------------------------------------------------
|
| Enables SKUs to be automatically generated on item creation.
|
*/
'skus_enabled' => true,
/*
|--------------------------------------------------------------------------
| Sku Prefix Length
|--------------------------------------------------------------------------
|
| The sku prefix length, not including the code for example:
|
| An item with a category named 'Sauce', the sku prefix generated will be: SAU
|
*/
'sku_prefix_length' => 3,
/*
|--------------------------------------------------------------------------
| Sku Code Length
|--------------------------------------------------------------------------
|
| The sku code length, not including prefix for example:
|
| An item with an ID of 1 (one) the sku code will be: 000001
|
*/
'sku_code_length' => 6,
/*
* The sku separator for use in separating the prefix from the code.
*
* For example, if a hyphen (-) is inserted in the string below, a possible
* SKU might be 'DRI-00001'
*
* @var string
*/
/*
|--------------------------------------------------------------------------
| Sku Separator
|--------------------------------------------------------------------------
|
| The sku separator for use in separating the prefix from the code.
|
| For example, if a hyphen (-) is inserted in the string
| below, a possible SKU might be 'DRI-00001'
|
*/
'sku_separator' => '',
];
用法
将 HasInventory 添加到模型中,该特性将启用库存跟踪。
...
use Controlla\Inventory\HasInventory;
class Product extends Model
{
use HasInventory;
...
}
函数
...
$product = Product::first();
$product->set(10); // $product->currentInventory()->quantity; (Will result in 10)
$product->currentInventory() //Return inventory instance
$product->add(5); // $product->currentInventory()->quantity; (Will result in 15)
$product->take(5); // $product->currentInventory()->quantity; (Will result in 10)
$product->inInventory(); // Return true
$product->clearInventory(); // $product->currentInventory(); (return null)
$product->notInInventory(); // Return true
--- Scopes ---
Product::InventoryIs(10)->get(); // Return all products with inventory of 10
Product::InventoryIs(10, '>=')->get(); // Return all products with inventory of 10 or greater
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]
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
用法
该包触发以下事件
InventoryUpdate:库存更改。
测试
composer test
变更日志
请参阅 变更日志 以获取有关最近更改的更多信息。
贡献
请参阅 贡献指南 了解详情。
安全漏洞
请参阅 我们的安全策略 了解如何报告安全漏洞。
鸣谢
许可证
MIT 许可证 (MIT)。请参阅 许可证文件 了解更多信息。
