Laravel - export excel laravel data tidak bertambah

<?php

namespace App\Exports;
use App\ModelDataAsset2;
use App\Test;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Maatwebsite\Excel\Concerns\WithEvents;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use Maatwebsite\Excel\Events\AfterSheet;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;

class AssetExport implements FromView, ShouldAutoSize, WithEvents
{
    /**
    * @return \Illuminate\Support\Collection
    */

    public function view(): View
   {
       return view('exel_view', [
           'data' => ModelDataAsset2::all()
       ]);
   }

   public function registerEvents(): array
    {
        return [
            AfterSheet::class   => function(AfterSheet $event) {
                  $event->sheet->styleCells(
                       'A1:B1',[
                         //Set background Style
                              'fill' => [
                             'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
                             'startColor' => [
                                 'rgb' => '92d050',
                              ]
                         ],
                      ]

                  );
                  $event->sheet->styleCells(
                       'C1:M1',[
                        //Set background Style
                             'fill' => [
                            'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
                            'startColor' => [
                                 'rgb' => 'ffff00',
                             ]
                        ],
                       ]

                  );
                  $event->sheet->styleCells(
                       'N1:AE1',[
                        //Set background Style
                             'fill' => [
                            'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
                            'startColor' => [
                                 'rgb' => 'ffc000',
                             ]
                        ],
                       ]

                  );
                  $event->sheet->styleCells(
                       'AF1:BA1',[
                        //Set background Style
                             'fill' => [
                            'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
                            'startColor' => [
                                 'rgb' => '00b0f0',
                             ]
                        ],
                       ]

                  );
                  $event->sheet->styleCells(
                       'BB1:BL1',[
                        //Set background Style
                             'fill' => [
                            'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
                            'startColor' => [
                                 'rgb' => '92d050',
                             ]
                        ],
                       ]

                  );
                  $event->sheet->styleCells(
                       'BM1:BS1',[
                        //Set background Style
                             'fill' => [
                            'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
                            'startColor' => [
                                 'rgb' => 'ff0000',
                             ]
                        ],
                       ]

                  );
                  $event->sheet->styleCells(
                       'BT1:CN1',[
                        //Set background Style
                             'fill' => [
                            'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
                            'startColor' => [
                                 'rgb' => '929292',
                             ]
                        ],
                       ]

                  );
            },
        ];
    }

}

saya pake laravel Maatwebsite, saya mau export data dari database ke excel, pertama kali export berhasil tapi setelah saya tambahin data baru di database terus saya export lagi ternyata si data baru ini ga nambah..

Tolong bantu saya..

avatar rizki198
@rizki198

2 Kontribusi 0 Poin

Dipost 4 tahun yang lalu

Tanggapan

tolong codenya dipaste kan disini sesuai dengan kaidah forum :)

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban