chartOfAccountFacade = app(ChartOfAccountFacade::class); } /** * @param Collection $collection */ public function collection(Collection $collection) { foreach ($collection as $i => $row) { if ($i != 0) { $name = $row[0]; $code = $row[1]; $type = keyChartOfAccountType($row[2]); $parentName = $row[3]; $parentType = keyChartOfAccountType($row[4]); $debit = $row[5]; $credit = $row[6]; $description = $row[7]; $parent = $parentName ? $this->chartOfAccountFacade->findByNameOrCreate( (new ChartOfAccountAttr) ->setName($parentName) ->setType($parentType) ) : null; $this->chartOfAccountFacade->findByNameOrCreate( (new ChartOfAccountAttr) ->setName($name) ->setType($type) ->setCode($code) ->setChartOfAccountId($parent->id ?? null) ->setDebits($debit) ->setCredits($credit) ->setDescription($description) ); } } } }