Advertisement
fadlyshafa

Untitled

Apr 17th, 2020
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.82 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Imports;
  4.  
  5. use App\Models\M_produk;
  6. use Maatwebsite\Excel\Concerns\ToModel;
  7. use Illuminate\Support\Collection;
  8. use Maatwebsite\Excel\Concerns\ToCollection;
  9.  
  10. class ProdukImport implements ToCollection
  11. {
  12.     /**
  13.     * @param array $row
  14.     *
  15.     * @return \Illuminate\Database\Eloquent\Model|null
  16.     */
  17.     public function collection(Collection $rows)
  18.     {
  19.         // dd($rows);
  20.         // M_produk::insert($rows);
  21.         foreach ($rows as $e=>$row)
  22.         {
  23.             if($e == 0){
  24.                 continue;
  25.             }
  26.             // dd($row[1]);
  27.             M_produk::insert([
  28.                 'supplier'=>$row[0],
  29.                 'nama'=>$row[1],
  30.                 'kode'=>$row[2],
  31.                 'stock'=>$row[3],
  32.                 'minimal_stock'=>$row[4],
  33.                 'buy'=>$row[5],
  34.                 'harga'=>$row[6],
  35.                 'harga_grosir'=>$row[7],
  36.                 'kategori'=>$row[8],
  37.                 'seri'=>$row[9],
  38.                 'satuan'=>$row[10],
  39.                 'size'=>$row[11],
  40.                 'berat'=>$row[12],
  41.             ]);
  42.             // dd($bege);
  43.         //     User::create([
  44.         //         'name' => $row[0],
  45.         //     ]);
  46.         }
  47.     }
  48.     // public function model(array $row)
  49.     // {
  50.     //     // dd($row);
  51.     //     return new M_produk([
  52.     //         'supplier'=>$row[0],
  53.     //         'nama'=>$row[1],
  54.     //         'kode'=>$row[2],
  55.     //         'stock'=>$row[3],
  56.     //         'minimal_stock'=>$row[4],
  57.     //         'buy'=>$row[5],
  58.     //         'harga'=>$row[6],
  59.     //         'harga_grosir'=>$row[7],
  60.     //         'kategori'=>$row[8],
  61.     //         'seri'=>$row[9],
  62.     //         'satuan'=>$row[10],
  63.     //         'size'=>$row[11],
  64.     //         'berat'=>$row[12],
  65.     //     ]);
  66.     // }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement