public function laporansimpananexport($bulan, $tahun) { $data = array(); $data = \App\Transaksi::where('id_koperasi', Auth::user()->assigned_koperasi)->where('created_at', 'like', $tahun . "-%" . $bulan . "-%")->where('jenis_transaksi', 'Simpanan')->get(); $export = array(); foreach ($data as $key) { $export[] = array('Tanggal' => date_format(date_create($key->created_at), "d") . " " . \App\Bulan::where('bulan', date_format(date_create($key->created_at), "m"))->first()['nama'] . " " . date_format(date_create($key->created_at), "Y"), 'Nama' => \App\Anggota::where('id_koperasi', Auth::user()->assigned_koperasi)->find($key->id_anggota)['nama'], 'Jenis' => \App\Simpanan::where('id_koperasi', Auth::user()->assigned_koperasi)->find($key->id_jenis)['nama'], 'Jumlah' => (int) $key->jumlah_total); } Excel::create('Laporan Simpanan', function ($excel) use($export) { $excel->sheet('Laporan Simpanan', function ($sheet) use($export) { $sheet->fromArray($export); }); })->download('xls'); }