0
我使用一個命令添加產品從API到我的數據庫使用下面的代碼Laravel 5.1命令空表
class UpdateCatalog extends Command {
protected $name = 'catalog:update';
protected $description = 'Command description.';
public function __construct()
{
parent::__construct();
}
public function fire()
{
$products = Api::productsGetProducts();
foreach($products as $product)
{
$detail = Api::productsGetProduct($product['id']);
$product = new Product();
$product->id = $detail->getId();
$product->external_id = $detail->getExternalId();
$product->name = $detail->getName();
$product->description = $detail->getDescription();
$product->thumbnail = $detail->getThumbnail();
$product->price = $detail->getPrices()[0]['price_excl_vat'];
$product->vat = $detail->getVat();
$product->save();
}
}
}
現在我想知道是否有可能爲空表之前,再次填充它。
謝謝!
啊哈謝謝!我一定在文檔中錯過了這個。 – Notflip
我的ID在使用後不斷上升。 – ihue