public function families() { return Family::whereIn("id", $this->users()->whereNotNull("family_id")->select('family_id')->lists('family_id'))->get(); // or whatever your namespace is }
/** * @param $ids */ public function exportPdf($ids = null) { $ids = explode(',', substr($ids, 0, -1)); $ids = array_unique($ids); $family = Family::whereIn('id', $ids)->where('user_id', \Auth::user()->id)->get(['id', 'responsable', 'nom_pere', 'nom_mere']); Excel::create('La liste des familles', function ($excel) use($family, $ids) { $excel->sheet('La liste des familles', function ($sheet) use($family, $ids) { foreach ($family as $f) { $count = 0; if ($f->responsable == 0) { $f->responsable = $f->nom_mere; } else { $f->responsable = $f->nom_pere; } foreach ($f->children as $c) { foreach ($c->bills as $b) { if ($b->status == 0) { $count += 1; } } } if ($count > 0) { $f->status = 'Non Réglée'; } else { $f->status = 'Réglée'; } unset($f->id); } $sheet->setWidth('A', 20); $sheet->setWidth('B', 20); $sheet->setWidth('C', 20); $sheet->setWidth('D', 20); $sheet->fromModel($family); $sheet->setAllBorders('thin'); $sheet->setFontFamily('OpenSans'); $sheet->setFontSize(13); $sheet->setFontBold(false); 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 . ':' . 'D' . $i, function ($cells) { $cells->setValignment('middle'); $cells->setFontColor('#556b7b'); $cells->setFont(array('family' => 'OpenSans', 'size' => '13', 'bold' => false)); }); } // normal header $sheet->cells('A1:D1', function ($cells) { $cells->setBackground('#e9f1f3'); $cells->setFontColor('#556b7b'); $cells->setFont(array('family' => 'OpenSans', 'size' => '15', 'bold' => true)); }); $sheet->row(1, array('Responsable', 'Nom Père', 'Nom Mère', 'Statut de Paiement')); }); })->export('pdf'); }