CourseImport.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Imports;
  3. use Carbon\Carbon;
  4. use Maatwebsite\Excel\Concerns\ToModel;
  5. use Maatwebsite\Excel\Concerns\Importable;
  6. use Maatwebsite\Excel\Concerns\SkipsOnError;
  7. use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
  8. use Maatwebsite\Excel\Concerns\WithHeadingRow;
  9. use Maatwebsite\Excel\Concerns\WithBatchInserts;
  10. use Maatwebsite\Excel\Concerns\WithChunkReading;
  11. use Maatwebsite\Excel\Concerns\RemembersRowNumber;
  12. class CourseImport implements ToModel, SkipsOnError, WithHeadingRow, WithChunkReading, WithBatchInserts
  13. {
  14. use Importable, RemembersRowNumber;
  15. private $imported_list = [];
  16. public function model(array $row){
  17. $insertArray = [
  18. 'name' => $row['coursename'],
  19. 'institute' => $row['university'],
  20. 'campuses' => $row['campus'],
  21. 'level' => $row['level'],
  22. 'department' => $row['department'],
  23. 'length' => $row['courselength'],
  24. 'intakes' => $row['intake'],
  25. 'toefl' => $row['toefl'],
  26. 'ielts' => $row['ielts'],
  27. 'duolingo' => $row['duolingo'],
  28. 'pte' => $row['pte'],
  29. 'tuitionfee' => $row['tuitionfee'],
  30. 'scholarship' => $row['scholarship'],
  31. 'depositrequired' => $row['depositrequired'],
  32. 'reference' => $row['reference'],
  33. 'sop' => $row['sop'],
  34. 'cv' => $row['cv'],
  35. 'entryrequirement' => $row['entryrequirement'],
  36. 'tags' => $row['tags'],
  37. ];
  38. array_push($this->imported_list, $insertArray);
  39. }
  40. public function getImportedRows()
  41. {
  42. return $this->imported_list;
  43. }
  44. public function onError(\Throwable $e)
  45. {
  46. return res_msg('File import failed!', 403);
  47. }
  48. public function batchSize(): int
  49. {
  50. return 100;
  51. }
  52. public function chunkSize(): int
  53. {
  54. return 100;
  55. }
  56. }