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

hamiddz's avatar

dom-pdf laravel array

Hi I'm trying to pass a data to my view fro dompdf but I cannot my controller creatpdf function $orm = (new ordreResource(Ordremouvement::find($id)))->resolve();

    $projectO       = $orm['chantierOrigin'];
    $projectD        = $orm['chantierDestination'];
    $emps             = $orm['employes'];
    $dateplustot    = $orm['dateplutot'];
    $dateplustard   = $orm['dateplutard'];//*/
    $pdf = PDF::loadView('ordrem',compact('projectO','projectD','emps','dateplustot','dateplustard'));
    $pdf->setPaper('a4','landscape');
    return $pdf->download('om.pdf');//*/

on my view fro dompdf I have this

@foreach ($emps as $item) {{$item->nom}} {{$item->prenom}} {{$item->dateNaissance }} / / / {{ $dateplustot }} {{ $dateplustot }} {{ $dateplustard }} {{ $dateplustard }} @endforeach

the $item is empty i get nothing from it however i get the value of others any solutions !!

0 likes
2 replies
Sinnbeck's avatar

I am not sure what you mean? I assume $item is a model so how do you mean that it's empty? Do you mean that {{$item->nom}} outputs nothing?

Also please format your code by adding ``` on the line before and after it

1 like
hamiddz's avatar

@sinnbeck yes i have the {{$item->nom}} output nothing. did i make an error when transfering the data to the view ? or i'm formating my $emps = $orm['employes'] badly ?

Please or to participate in this conversation.