public function exportPdf($ids = null) { $ids = explode(',', substr($ids, 0, -1)); $ids = array_unique($ids); $model = Bill::whereIn('id', $ids)->where('user_id', \Auth::user()->id)->get(['id', 'child_id', 'start', 'somme', 'status']); Excel::create('La liste des Factures', function ($excel) use($model, $ids) { $excel->sheet('La liste des Factures', function ($sheet) use($model, $ids) { foreach ($model as $bill) { $bill->date = $bill->start->toDateString(); if ($bill->status == 0) { $bill->status = 'Non Réglée'; } else { $bill->status = 'Réglée'; } $bill->child_id = Child::where('id', $bill->child_id)->first()->nom_enfant; unset($bill->start); } $sheet->setWidth('A', 15); $sheet->setWidth('B', 15); $sheet->setWidth('C', 15); $sheet->setWidth('D', 15); $sheet->setWidth('E', 15); $sheet->fromModel($model); $sheet->setAllBorders('thin'); $sheet->setFontFamily('OpenSans'); $sheet->setFontSize(13); $sheet->setFontBold(false); $sheet->setAllBorders('thin'); for ($i = 1; $i <= count($ids) + 1; $i++) { $sheet->row($i, function ($rows) { $rows->setFontColor('#556b7b'); $rows->setAlignment('center'); }); } $sheet->cells('A1:E1', function ($cells) { $cells->setBackground('#e9f1f3'); $cells->setFontColor('#556b7b'); $cells->setFont(array('family' => 'OpenSans', 'size' => '15', 'bold' => true)); }); $sheet->row(1, array('Num De Facture', 'Nom de l\'élève', 'Somme', 'Statut', 'Date')); }); })->export('pdf'); }