I'm trying to download a PDF with all my register user email. The problem is that when i download the PDF, he is empty
I have a controller that create the PDF and with a compact i send all my data to my view. In my view i display all the data with a foreach
When i print_r the data in my controller, it work, but in my pdf i have nothing. So i think the problem comes from the compact
public function generatePDF(int $id)
{
$inscrit = Like::where('type',3)->where('id_event' , $id )->first();
$pdf = PDF::loadView('myPDF', compact('inscrit'));
return $pdf->download('Inscrits.pdf');
}
<!DOCTYPE html>
<html>
<head>
<title>Inscrits</title>
</head>
<body>
<h1> Inscrits pour l'événement : </h1>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<tr>
<td>
{{$inscrit->email}}
<td>
</td>
</tr>
</body>
</html>
Just try to dd your $inscrit variable like dd($inscrit) just to know that you fetch the data.
and you say you want to get all register user but your query is using the first() method. try to use get()