Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function handle()
- {
- if (false === file_exists($this->argument('file'))) {
- throw new FileNotFoundException('File not found');
- }
- $this->file = $this->argument('file');
- $this->comment('--- Start reading CSV file ---');
- $handle = fopen($this->file, "r");
- $outPutCsvLine = [];
- while ($csvLine = fgetcsv($handle, 1000, ',')) {
- $data = [
- 'name' => $csvLine[0];
- 'category_id' => $this->searchCategoryByName($csvLine[1])
- ];
- $this->createOrUpdateAliment($data);
- }
- }
- private function createOrUpdateAliment($data) {
- $aliment = AppAliment::where('name',$name)->first();
- if (null === $aliment) {
- $aliment->create($data);
- }
- else {
- .... // actualizar
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement