示例#1
0
 public function exportPdf($ids = null)
 {
     $ids = explode(',', substr($ids, 0, -1));
     $ids = array_unique($ids);
     $model = Classroom::whereIn('id', $ids)->where('user_id', \Auth::user()->id)->get(['nom_classe', 'code_classe', 'capacite_classe', 'niveau', 'branche']);
     Excel::create('La liste des Classes', function ($excel) use($model, $ids) {
         $excel->sheet('La liste des Classes', function ($sheet) use($model, $ids) {
             foreach ($model as $item) {
                 if ($item->niveau) {
                     $item->niveau = \Auth::user()->leslevels()->where('id', $item->niveau)->first()->niveau;
                 } else {
                     $item->niveau = '--';
                 }
                 if ($item->branche) {
                     $item->branche = \Auth::user()->branches()->where('id', $item->branche)->first()->nom_branche;
                 } else {
                     $item->branche = '--';
                 }
             }
             $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->setHeight($i, 25);
                 $sheet->row($i, function ($rows) {
                     $rows->setFontColor('#556b7b');
                     $rows->setAlignment('center');
                 });
                 $sheet->cells('A' . $i . ':' . 'E' . $i, function ($cells) {
                     $cells->setValignment('middle');
                     $cells->setFontColor('#556b7b');
                     $cells->setFont(array('family' => 'OpenSans', 'size' => '13', 'bold' => false));
                 });
             }
             // normal header
             $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('Nom de la Classe', 'Code de la Classe', 'Capacité de la Classe', 'Niveau', 'Branche'));
         });
     })->export('pdf');
 }