laravel-dompdf
laravel-dompdf copied to clipboard
undefined data in blade view
$data = User::all()->toArray(); $pdf = Pdf::loadView('users/pdf', $data); return $pdf->download('usersPDF.pdf'); in pdf.blade.php which is the view receives $data you can see error (undefined variable $data) . could you help me about it ?
this is balde file:
@extends('index') @section('content')
| # | First Name | Last Name | UserName | Grade | Father Name |
|---|
Read laravel documentation That is not how the data is sent to the views
that should be
$data = User::all();
$pdf = Pdf::loadView('users/pdf', compact('data'));
I had the same problem, this works for me:
$pdf = Pdf::loadView('users/pdf', ['data'] => $data);