/** * Execute the console command. * * @return mixed */ public function fire() { $companyListFromASX = UpdateStockListCommand::getCompanyList($this->option('testMode')); $numberOfStocks = count($companyListFromASX); foreach ($companyListFromASX as $key => $companyRow) { if ($companyRow != null) { $stockCode = explode(',"', explode('",', $companyRow)[1])[0]; Stock::updateOrCreate(['stock_code' => $stockCode], ['stock_code' => explode(',"', explode('",', $companyRow)[1])[0], 'company_name' => formatCompanyName($stockCode, substr(explode('",', $companyRow)[0], 1)), 'sector' => substr(explode(',"', explode('",', $companyRow)[1])[1], 0, -2), 'updated_at' => date("Y-m-d H:i:s")]); $this->info("Updating... " . round(($key + 1) * (100 / $numberOfStocks), 2) . "%"); } } $this->info('The list of stocks was updated successfully!'); }