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

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

Creates an SKU with the specified code. If overwrite is true, the current items SKU will be deleted if it exists before creating then SKU. If overwrite is false but the item has an SKU, an exception is thrown.
public createSku ( string $code, boolean $overwrite = false ) : mixed | boolean
$code string
$overwrite boolean
Результат mixed | boolean
    public function createSku($code, $overwrite = false)
    {
        // Get the current SKU record
        $sku = $this->sku()->first();
        if ($sku) {
            // The dev doesn't want the SKU overridden, we'll thrown an exception
            if (!$overwrite) {
                $message = Lang::get('inventory::exceptions.SkuAlreadyExistsException');
                throw new SkuAlreadyExistsException($message);
            }
            // Overwrite is true, lets update the current SKU
            return $this->updateSku($code, $sku);
        }
        // No SKU exists, lets create one
        return $this->processSkuGeneration($this->getKey(), $code);
    }