PHP code example of vivek-mistry / laravel-inventory-core

1. Go to this page and download the library: Download vivek-mistry/laravel-inventory-core library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vivek-mistry / laravel-inventory-core example snippets


return [
    'default_warehouse' => null,
    'allow_negative_stock' => false,
    'low_stock_threshold' => 5,
];

use VivekMistry\InventoryCore\Traits\Stockable;

class Product extends Model
{
    use Stockable;
}

$product->addStock(100);

$product->addStock(50, ['reason' => 'Initial stock'], warehouseId: 1);

$product->reduceStock(5);

$product->reserveStock(2);

$product->reserveStock(2, warehouseId: 1);

$product->releaseStock(2);

$product->availableStock(); // quantity - reserved
$product->reservedStock();

InventoryWarehouse::create([
    'name' => 'Main Warehouse',
    'code' => 'MAIN',
    'is_default' => true,
]);

'low_stock_threshold' => 5,

use InventoryCore\Events\LowStockDetected;

Event::listen(LowStockDetected::class, function ($event) {
    // Send email, Slack, notification, etc.
});

## 🧪 Example Flow (Real-World)
$product->addStock(100);
$product->reserveStock(10);   // Cart
$product->availableStock();   // 90
$product->releaseStock(5);    // Cart cancelled
$product->reduceStock(5);   

vendor/bin/phpuit
bash
php artisan vendor:publish --tag=inventory-config
bash
php artisan migrate