Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jake214's avatar

How to pass multiple arrays/objects into DOMPDF?

Currently, when I pass arrays/objects into a view I do it like this:

However, the readme.md says I should use DOMPDF like this:

How do I pass my objects into this view?

0 likes
6 replies
Sinnbeck's avatar
$pdf = PDF::loadView('pdf.invoice', ['dates' => $dates]);
//or
$pdf = PDF::loadView('pdf.invoice', compact('dates'));
jake214's avatar

@Sinnbeck

ArgumentCountError

Too few arguments to function App\Http\Controllers\AppointmentController::downloadPdf(), 0 passed in C:\xampp\htdocs\Appointment_Form\vendor\laravel\framework\src\Illuminate\Routing\Controller.php on line 54 and exactly 1 expected

Sinnbeck's avatar

@jake214 So you are expecting a date.

<form action="{{ route('view-pdf') }}" method="POST" target="__blank">
    @csrf
    <input type="hidden" name="date"  value="{{now()->toDateString()}}" />
    <button type="submit" style="float: right">Export</button>
</form>

and fix the method

public function downloadPdf(Request $request){
    $selectedDate = $request->input('date'); //get it from the form
    $dates = usersappointments::query()
    ->when($selectedDate, function ($query, $selectedDate) {
        $query->where('date', $selectedDate);
    })
    ->get()
    ->groupBy('date');

    $pdf = PDF::loadView('Appointments.usersAppointmentsGroup', ['dates' => $dates]);

    return $pdf->download('users-details.pdf');
}

Please or to participate in this conversation.