Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
256 changes: 24 additions & 232 deletions docs/INSTALLATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,240 +89,32 @@ If you'd like to use them you'll have include them in your use statements:

### I want to customize my models

Create the models, but keep in mind the models need:
Create the models, extend the existing models and add the new models to the models array in app/config/inventory.php.

- The shown fillable attribute arrays (needed for dynamically creating & updating relationship records)
- The shown relationship names (such as `stocks()`)
- The shown relationship type (such as hasOne, hasMany, belongsTo etc)
You are free to modify anything (such as table names, model names, namespace etc!).

You are free to modify anything else (such as table names, model names, namespace etc!).
Example:

Metric:

class Metric extends Model
{
protected $table = 'metrics';
}

Location:

use Baum\Node;

class Location extends Node
{
protected $table = 'locations';
}

Category:

use Stevebauman\Inventory\Traits\CategoryTrait;
use Baum\Node;

class Category extends Node
{
use CategoryTrait;

protected $table = 'categories';

protected $scoped = ['belongs_to'];

public function inventories()
{
return $this->hasMany('Inventory', 'category_id');
}
}

Supplier:

use Stevebauman\Inventory\Traits\SupplierTrait;

class Supplier extends BaseModel
{
use SupplierTrait;

protected $table = 'suppliers';

public function items()
{
return $this->belongsToMany('Inventory', 'inventory_suppliers', 'supplier_id')->withTimestamps();
}
}

Inventory:

use Stevebauman\Inventory\Traits\InventoryTrait;
use Stevebauman\Inventory\Traits\InventoryVariantTrait;

class Inventory extends Model
{
use InventoryTrait;
use InventoryVariantTrait;

protected $table = 'inventory';

public function category()
{
return $this->hasOne('Category', 'id', 'category_id');
}

public function metric()
{
return $this->hasOne('Metric', 'id', 'metric_id');
}

public function sku()
{
return $this->hasOne('InventorySku', 'inventory_id', 'id');
}

public function stocks()
{
return $this->hasMany('InventoryStock', 'inventory_id');
}

public function suppliers()
{
return $this->belongsToMany('Supplier', 'inventory_suppliers', 'inventory_id')->withTimestamps();
}
}

InventorySku:

use Stevebauman\Inventory\Traits\InventorySkuTrait;

class InventorySku extends Model
{
use InventorySkuTrait;

protected $table = 'inventory_skus';

protected $fillable = array(
'inventory_id',
'code',
);

public function item()
{
return $this->belongsTo('Inventory', 'inventory_id', 'id');
}
}

InventoryStock:

use Stevebauman\Inventory\Traits\InventoryStockTrait;

class InventoryStock extends Model
{
use InventoryStockTrait;

protected $table = 'inventory_stocks';

protected $fillable = array(
'inventory_id',
'location_id',
'quantity',
'aisle',
'row',
'bin',
);

public function item()
{
return $this->belongsTo('Inventory', 'inventory_id', 'id');
}

public function movements()
{
return $this->hasMany('InventoryStockMovement', 'stock_id');
}

public function transactions()
{
return $this->hasMany('InventoryTransaction', 'stock_id', 'id');
}

public function location()
{
return $this->hasOne('Location', 'id', 'location_id');
}
}

InventoryStockMovement:

use Stevebauman\Inventory\Traits\InventoryStockMovementTrait;

class InventoryStockMovement extends Model
{
use InventoryStockMovementTrait;

protected $table = 'inventory_stock_movements';

protected $fillable = array(
'stock_id',
'user_id',
'before',
'after',
'cost',
'reason',
);

public function stock()
{
return $this->belongsTo('InventoryStock', 'stock_id', 'id');
}
}

InventoryTransaction:

use Stevebauman\Inventory\Traits\InventoryTransactionTrait;
use Stevebauman\Inventory\Interfaces\StateableInterface;

class InventoryTransaction extends BaseModel implements StateableInterface
{
use InventoryTransactionTrait;

protected $table = 'inventory_transactions';

protected $fillable = array(
'user_id',
'stock_id',
'name',
'state',
'quantity',
);

public function stock()
{
return $this->belongsTo('InventoryStock', 'stock_id', 'id');
}

public function histories()
{
return $this->hasMany('InventoryTransactionHistory', 'transaction_id', 'id');
}
}

InventoryTransactionHistory:

use Stevebauman\Inventory\Traits\InventoryTransactionHistoryTrait;

class InventoryTransactionHistory extends BaseModel
{
use InventoryTransactionHistoryTrait;

protected $table = 'inventory_transaction_histories';

protected $fillable = array(
'user_id',
'transaction_id',
'state_before',
'state_after',
'quantity_before',
'quantity_after',
);

public function transaction()
{
return $this->belongsTo('InventoryTransaction', 'transaction_id', 'id');
}
}
Create your model:
```
<?php
namespace App\InventoryStock;

class InventoryStock extends \Stevebauman\Inventory\Models\InventoryStock
{
// ...
}
```

and then modify the models array in app/config/inventory.php to use your new class:
```
...
'models' => [
...
'inventory_stock' => 'App\InventoryStock',
...
],
...
```
2 changes: 1 addition & 1 deletion src/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ class Category extends Node
*/
public function inventories()
{
return $this->hasMany('Stevebauman\Inventory\Models\Inventory', 'category_id', 'id');
return $this->hasMany(config('inventory.models.inventory'), 'category_id', 'id');
}
}
10 changes: 5 additions & 5 deletions src/Models/Inventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Inventory extends BaseModel
*/
public function category()
{
return $this->hasOne('Stevebauman\Inventory\Models\Category', 'id', 'category_id');
return $this->hasOne(config('inventory.models.category'), 'id', 'category_id');
}

/**
Expand All @@ -36,7 +36,7 @@ public function category()
*/
public function metric()
{
return $this->hasOne('Stevebauman\Inventory\Models\Metric', 'id', 'metric_id');
return $this->hasOne(config('inventory.models.metric'), 'id', 'metric_id');
}

/**
Expand All @@ -46,7 +46,7 @@ public function metric()
*/
public function sku()
{
return $this->hasOne('Stevebauman\Inventory\Models\InventorySku', 'inventory_id', 'id');
return $this->hasOne(config('inventory.models.inventory_sku'), 'inventory_id', 'id');
}

/**
Expand All @@ -56,7 +56,7 @@ public function sku()
*/
public function stocks()
{
return $this->hasMany('Stevebauman\Inventory\Models\InventoryStock', 'inventory_id', 'id');
return $this->hasMany(config('inventory.models.inventory_stock'), 'inventory_id', 'id');
}

/**
Expand All @@ -66,7 +66,7 @@ public function stocks()
*/
public function suppliers()
{
return $this->belongsToMany('Stevebauman\Inventory\Models\Supplier', 'inventory_suppliers', 'inventory_id')->withTimestamps();
return $this->belongsToMany(config('inventory.models.supplier'), 'inventory_suppliers', 'inventory_id')->withTimestamps();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Models/InventorySku.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ class InventorySku extends BaseModel
*/
public function item()
{
return $this->belongsTo('Stevebauman\Inventory\Models\Inventory', 'inventory_id', 'id');
return $this->belongsTo(config('inventory.models.inventory'), 'inventory_id', 'id');
}
}
8 changes: 4 additions & 4 deletions src/Models/InventoryStock.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class InventoryStock extends BaseModel
*/
public function item()
{
return $this->belongsTo('Stevebauman\Inventory\Models\Inventory', 'inventory_id', 'id');
return $this->belongsTo(config('inventory.models.inventory'), 'inventory_id', 'id');
}

/**
Expand All @@ -32,7 +32,7 @@ public function item()
*/
public function movements()
{
return $this->hasMany('Stevebauman\Inventory\Models\InventoryStockMovement', 'stock_id', 'id');
return $this->hasMany(config('inventory.models.inventory_stock_movement'), 'stock_id', 'id');
}

/**
Expand All @@ -42,7 +42,7 @@ public function movements()
*/
public function transactions()
{
return $this->hasMany('Stevebauman\Inventory\Models\InventoryTransaction', 'stock_id', 'id');
return $this->hasMany(config('inventory.models.inventory_transaction'), 'stock_id', 'id');
}

/**
Expand All @@ -52,6 +52,6 @@ public function transactions()
*/
public function location()
{
return $this->hasOne('Stevebauman\Inventory\Models\Location', 'id', 'location_id');
return $this->hasOne(config('inventory.models.location'), 'id', 'location_id');
}
}
2 changes: 1 addition & 1 deletion src/Models/InventoryStockMovement.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ class InventoryStockMovement extends BaseModel
*/
public function stock()
{
return $this->belongsTo('Stevebauman\Inventory\Models\InventoryStock', 'stock_id', 'id');
return $this->belongsTo(config('inventory.models.inventory_stock'), 'stock_id', 'id');
}
}
4 changes: 2 additions & 2 deletions src/Models/InventoryTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class InventoryTransaction extends BaseModel implements StateableInterface
*/
public function stock()
{
return $this->belongsTo('Stevebauman\Inventory\Models\InventoryStock', 'stock_id', 'id');
return $this->belongsTo(config('inventory.models.inventory_stock'), 'stock_id', 'id');
}

/**
Expand All @@ -33,6 +33,6 @@ public function stock()
*/
public function histories()
{
return $this->hasMany('Stevebauman\Inventory\Models\InventoryTransactionHistory', 'transaction_id', 'id');
return $this->hasMany(config('inventory.models.inventory_transaction_history'), 'transaction_id', 'id');
}
}
2 changes: 1 addition & 1 deletion src/Models/InventoryTransactionHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ class InventoryTransactionHistory extends BaseModel
*/
public function transaction()
{
return $this->belongsTo('Stevebauman\Inventory\Models\InventoryTransaction', 'transaction_id', 'id');
return $this->belongsTo(config('inventory.models.inventory_transaction'), 'transaction_id', 'id');
}
}
Loading