customerFacade = app(CustomerFacade::class); $this->provinceRepository = app(ProvinceRepositoryInterface::class); $this->cityRepository = app(CityRepositoryInterface::class); $this->subdistrictRepository = app(SubdistrictRepositoryInterface::class); $this->subdistrictAreaRepository = app(SubdistrictAreaRepositoryInterface::class); } /** * @param Collection $collection */ public function collection(Collection $collection) { foreach ($collection as $i => $row) { if ($i > 0) { $name = $row[0]; $email = $row[1]; $phoneNumber = $row[2]; $province = $this->provinceRepository->findByNameLowerStr($row[3]); $city = $this->cityRepository->findByNameLowerStr($row[4]); $subdistrict = $this->subdistrictRepository->findByNameLowerStr($row[5]); $subdistrictArea = $this->subdistrictAreaRepository->findByNameLowerStr($row[6]); $address = $row[7]; $this->customerFacade->findByNameOrCreate( (new CustomerAttr) ->setName($name) ->setEmail($email) ->setPhoneNumber($phoneNumber) ->setProvinceId($province->id ?? null) ->setCityId($city->id ?? null) ->setSubdistrictId($subdistrict->id ?? null) ->setSubdistrictAreaId($subdistrictArea->id ?? null) ->setAddress($address) ); } } } }