1. Go to this page and download the library: Download aiarmada/inventory 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/ */
aiarmada / inventory example snippets
use AIArmada\Inventory\Contracts\InventoryableInterface;
use AIArmada\Inventory\Traits\HasInventory;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Model;
class Product extends Model implements InventoryableInterface
{
use HasUuids, HasInventory;
}
use AIArmada\Inventory\Facades\Inventory;
$product = Product::find($id);
$location = InventoryLocation::where('code', 'WAREHOUSE-A')->first();
// Receive inventory
$product->receive($location->id, 100, 'Initial stock');
// Ship inventory
$product->ship($location->id, 5, 'sale', 'ORDER-123');
// Transfer between locations
$product->transfer($fromLocationId, $toLocationId, 20);
// Check availability
$total = $product->getTotalAvailable(); // All locations
$atLocation = $product->getInventoryAtLocation($locationId);
// Check if sufficient inventory exists
$product->hasInventory(10); // true if >= 10 available across all locations
// config/inventory.php
'allocation_strategy' => 'priority',
// Or via .env
INVENTORY_ALLOCATION_STRATEGY=priority
// In your Product model
public function getAllocationStrategy(): ?AllocationStrategy
{
return $this->allocation_strategy
? AllocationStrategy::from($this->allocation_strategy)
: null; // null = use global config
}
// Product needs 100 units, Warehouse A has 60, Warehouse B has 50
$allocations = InventoryAllocation::allocate($product, 100, 'cart-123');
// Returns 2 allocations:
// - 60 from Warehouse A
// - 40 from Warehouse B