skip to Main Content

I have export single image successfully. but I cant export multiple image. How to export multiple images in laravel excel ?

i get this error "Call to a member function setWorksheet() on array" using laravel excel maatwebsite-excel

public function drawings()
   {
       $Pengaduan = Pengaduan::select(
           'pengaduanTiket',
           'nama_lengkap',
           'no_hp',
           'no_kk',
           'no_ktp',
           'alamat_sesuai_ktp',
           'nama_pengaduan',
           'jenis_pengaduan',
           'isi_pengaduan',
           'status',
           'keterangan',
           'dokumen_pendukung',
           'dokumentasi',
           'lampiran',
       )->whereBetween('created_at', [$this->requestawal, $this->requestakhir])->get();


       $image1 = [];
       $image2 = [];
       $image3 = [];
       $rowNum = 2;
       foreach ($Pengaduan as $row) {

           $file1 = new Drawing();
           if ($row->dokumen_pendukung == null || $row->dokumen_pendukung == "") {
               $file1->setPath(public_path('/assets/images/default.jpg'));
           } else {
               $file1->setPath(public_path('/assets/uploads/images/pengaduan/') . $row->dokumen_pendukung);
           }
           $file1->setheight(20);
           $file1->setCoordinates('L' . $rowNum); 
           $image1[] = $file1;


           $file2 = new Drawing();
           if ($row->dokumentasi == null || $row->dokumentasi == "") {
               $file2->setPath(public_path('/assets/images/default.jpg'));
           } else {
               $file2->setPath(public_path('/assets/uploads/images/pengaduan/') . $row->dokumentasi);
           }
           $file2->setheight(20);
           $file2->setCoordinates('M' . $rowNum); 
           $image2[] = $file2;


           $file3 = new Drawing();
           if ($row->lampiran == null || $row->lampiran == "") {
               $file3->setPath(public_path('/assets/images/default.jpg'));
           } else {
               $file3->setPath(public_path('/assets/uploads/images/pengaduan/') . $row->lampiran);
           }
           $file3->setheight(20);
           $file3->setCoordinates('N' . $rowNum); 
           $image3[] = $file3;


           $rowNum++;
       }
       
       return [$image1, $image2, $image3];
   }

please help,

#It looks like your post is mostly code; please add some more details.
It looks like your post is mostly code; please add some more details.
It looks like your post is mostly code; please add some more details.
It looks like your post is mostly code; please add some more details.
It looks like your post is mostly code; please add some more details.
It looks like your post is mostly code; please add some more details.
It looks like your post is mostly code; please add some more details.

2

Answers


  1. Chosen as BEST ANSWER
    public function drawings()
        {
            $Pengaduan = Pengaduan::select(
                'pengaduanTiket',
                'nama_lengkap',
                'no_hp',
                'no_kk',
                'no_ktp',
                'alamat_sesuai_ktp',
                'nama_pengaduan',
                'jenis_pengaduan',
                'isi_pengaduan',
                'status',
                'keterangan',
                'dokumen_pendukung',
                'dokumentasi',
                'lampiran',
            )->whereBetween('created_at', [$this->requestawal, $this->requestakhir])->get();
    
    
            $gambar = [];
            $rowNum = 2;
            foreach ($Pengaduan as $row) {
    
                $file1 = new Drawing();
                if ($row->dokumen_pendukung == null || $row->dokumen_pendukung == "") {
                    $file1->setPath(public_path('/assets/images/default.jpg'));
                } else {
                    $file1->setPath(public_path('/assets/uploads/images/pengaduan/') . $row->dokumen_pendukung);
                }
                $file1->setheight(30);
                $file1->setCoordinates('L' . $rowNum);
                $gambar[] = $file1;
    
    
                $file2 = new Drawing();
                if ($row->dokumentasi == null || $row->dokumentasi == "") {
                    $file2->setPath(public_path('/assets/images/default.jpg'));
                } else {
                    $file2->setPath(public_path('/assets/uploads/images/pengaduan/') . $row->dokumentasi);
                }
                $file2->setheight(30);
                $file2->setCoordinates('M' . $rowNum);
                $gambar[] = $file2;
    
    
                $file3 = new Drawing();
                if ($row->lampiran == null || $row->lampiran == "") {
                    $file3->setPath(public_path('/assets/images/default.jpg'));
                } else {
                    $file3->setPath(public_path('/assets/uploads/images/pengaduan/') . $row->lampiran);
                }
                $file3->setheight(30);
                $file3->setCoordinates('N' . $rowNum);
                $gambar[] = $file3;
    
    
                $rowNum++;
            }
    
            return ($gambar);
        }
    

  2. Try:

    //...
    return [...$image1, ...$image2, ...$image3];
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search