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

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

Instantiates a new stock on the specified location on the current item.
public newStockOnLocation ( Model $location ) : Model
$location Illuminate\Database\Eloquent\Model
Результат Illuminate\Database\Eloquent\Model
    public function newStockOnLocation(Model $location)
    {
        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) {
            // Create a new stock model instance
            $stock = $this->stocks()->getRelated()->newInstance();
            // Assign the known attributes so devs don't have to
            $stock->setAttribute('inventory_id', $this->getKey());
            $stock->setAttribute('location_id', $location->getKey());
            return $stock;
        }
    }