PHP code example of caryley / laravel-inventory

1. Go to this page and download the library: Download caryley/laravel-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/ */

    

caryley / laravel-inventory example snippets


...
use Caryley\LaravelInventory\HasInventory;

class Product extends Model
{
    use HasInventory;

    ...
}

$product->hasValidInventory(); // Determine if the model has a valid inventory.

$product->setInventory(10); // $product->currentInventory()->quantity; (Will result in 10) | Not allowed to use negative numbers.

$product->currentInventory() //Return inventory instance if one exists, if not it will return null.

$product->addInventory(); // Will increment inventory by 1.

$product->addInventory(10); // Will increment inventory by 10.

$product->incrementInventory(10); // Will increment inventory by 10.

$product->subtractInventory(5); // Will subtract 5 from current inventory.

$product->subtractInventory(-5); // Will subtract 5 from current inventory.

$product->decrementInventory(5); // Will subtract 5 from current inventory.

$product->decrementInventory(-5); // Will subtract 5 from current inventory.

$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.

$product->notInInventory(); // Determine if model inventory is less than 0.

$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.

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

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
bash
php artisan vendor:publish --provider="Caryley\LaravelInventory\LaravelInventoryServiceProvider" --tag="migrations"
bash
php artisan vendor:publish --provider="Caryley\LaravelInventory\LaravelInventoryServiceProvider"
bash
php artisan migrate