Stevebauman\Inventory\Traits\InventoryTrait::createStockOnLocation PHP Метод

createStockOnLocation() публичный Метод

Creates a stock record to the current inventory item.
public createStockOnLocation ( integer | float | string $quantity, Model $location, string $reason = '', integer | float | string $cost, string $aisle = null, string $row = null, string $bin = null ) : Model
$quantity integer | float | string
$location Illuminate\Database\Eloquent\Model
$reason string
$cost integer | float | string
$aisle string
$row string
$bin string
Результат Illuminate\Database\Eloquent\Model
    public function createStockOnLocation($quantity, Model $location, $reason = '', $cost = 0, $aisle = null, $row = null, $bin = null)
    {
        try {
            // We want to make sure stock doesn't exist on the specified location already
            if ($this->getStockFromLocation($location)) {
                $message = Lang::get('inventory::exceptions.StockAlreadyExistsException', ['location' => $location->name]);
                throw new StockAlreadyExistsException($message);
            }
        } catch (StockNotFoundException $e) {
            // A stock record wasn't found on this location, we'll create one.
            $stock = $this->stocks()->getRelated()->newInstance();
            $stock->setAttribute('inventory_id', $this->getKey());
            $stock->setAttribute('location_id', $location->getKey());
            $stock->setAttribute('quantity', 0);
            $stock->setAttribute('aisle', $aisle);
            $stock->setAttribute('row', $row);
            $stock->setAttribute('bin', $bin);
            if ($stock->save()) {
                return $stock->put($quantity, $reason, $cost);
            }
        }
        return false;
    }