Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. public function handle()
  2. {
  3. if (false === file_exists($this->argument('file'))) {
  4. throw new FileNotFoundException('File not found');
  5. }
  6.  
  7. $this->file = $this->argument('file');
  8. $this->comment('--- Start reading CSV file ---');
  9.  
  10. $handle = fopen($this->file, "r");
  11.  
  12. $outPutCsvLine = [];
  13. while ($csvLine = fgetcsv($handle, 1000, ',')) {
  14. $data = [
  15. 'name' => $csvLine[0];
  16. 'category_id' => $this->searchCategoryByName($csvLine[1])
  17. ];
  18.  
  19. $this->createOrUpdateAliment($data);
  20. }
  21.  
  22.  
  23. }
  24.  
  25. private function createOrUpdateAliment($data) {
  26. $aliment = AppAliment::where('name',$name)->first();
  27.  
  28. if (null === $aliment) {
  29. $aliment->create($data);
  30. }
  31. else {
  32. .... // actualizar
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement