Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Imports;
- use App\Models\M_produk;
- use Maatwebsite\Excel\Concerns\ToModel;
- use Illuminate\Support\Collection;
- use Maatwebsite\Excel\Concerns\ToCollection;
- class ProdukImport implements ToCollection
- {
- /**
- * @param array $row
- *
- * @return \Illuminate\Database\Eloquent\Model|null
- */
- public function collection(Collection $rows)
- {
- // dd($rows);
- // M_produk::insert($rows);
- foreach ($rows as $e=>$row)
- {
- if($e == 0){
- continue;
- }
- // dd($row[1]);
- M_produk::insert([
- 'supplier'=>$row[0],
- 'nama'=>$row[1],
- 'kode'=>$row[2],
- 'stock'=>$row[3],
- 'minimal_stock'=>$row[4],
- 'buy'=>$row[5],
- 'harga'=>$row[6],
- 'harga_grosir'=>$row[7],
- 'kategori'=>$row[8],
- 'seri'=>$row[9],
- 'satuan'=>$row[10],
- 'size'=>$row[11],
- 'berat'=>$row[12],
- ]);
- // dd($bege);
- // User::create([
- // 'name' => $row[0],
- // ]);
- }
- }
- // public function model(array $row)
- // {
- // // dd($row);
- // return new M_produk([
- // 'supplier'=>$row[0],
- // 'nama'=>$row[1],
- // 'kode'=>$row[2],
- // 'stock'=>$row[3],
- // 'minimal_stock'=>$row[4],
- // 'buy'=>$row[5],
- // 'harga'=>$row[6],
- // 'harga_grosir'=>$row[7],
- // 'kategori'=>$row[8],
- // 'seri'=>$row[9],
- // 'satuan'=>$row[10],
- // 'size'=>$row[11],
- // 'berat'=>$row[12],
- // ]);
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement