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;
}
}