ismaelw / laratex

A Laravel package for creating PDF files using LaTeX
MIT License
105 stars 13 forks source link

How to pass and process data array to tex blade #22

Closed zillion42 closed 1 year ago

zillion42 commented 1 year ago

I have this kind of array each entry has a model and a collection of models:

2023-03-23 11_52_55-Start

I'm passing it to the tex blade like so: return (new LaraTeX('clerk.clerk_export_tex'))->with($daten)->download('test.pdf');

and I get 2023-03-23 11_53_35-🧨 Undefined variable_ daten (View_ D__Webappsrv_c_httpd_Apache24_htdocs_kranken

Originally posted by @zillion42 in https://github.com/ismaelw/laratex/issues/20#issuecomment-1480981605

zillion42 commented 1 year ago

Some more background. I create the array like so:

        foreach ($people as $person) {

            $rechnungen = $person->invoices->where('RJ', $rechnungsjahr)->sortByDesc('Produnktionstag');

            if (count($rechnungen) > 0) {
                $daten[] = [
                    'person' => $person,
                    'rechnungen' => $rechnungen
                ];
            }
        }

        return (new LaraTeX('clerk.clerk_export_tex'))->with($daten)->download('test.pdf');

and try to read it like so, I'm unsure if the access is correct yet, but it doesn't even recognize the array itself:

\begin{textblock}{12}(2.3,6)
\noindent
\begin{tabular}{ll}
@foreach($daten as $person)
SB & {{ $person['person']->Sachbearb }} \\
Name & {{ $person['person']->Nachname }} \\
Vorname & {{ $person['person']->Vorname }} \\
Geburtsdatum & {{ $person['person']->Geboren->isoFormat('DD.MM.YYYY'); }} \\
Stra{\ss}e & {{ $person['person']->Strasse }} \\
Ort & {{ $person['person']->Postleitzahl }} {{ $person['person']->Ort }} \\
ID & {{ $person['person']->id }} \\
\end{tabular}
\end{textblock}
\begin{textblock}{12}(2.45,10)
\noindent
\fontsize{10}{12} \selectfont
\begin{tabular}{|r|r|l|l|l|l|l|l|}
\hline 
% __tableHeader__
\hline
\hline 
% __tablebody__
\hline 
\end{tabular}
\end{textblock}

% ---- End Pages ------
@endforeach
ismaelw commented 1 year ago

Out of my head I think you would have to pass an array or use compact:

with(['daten', $daten])

or

with(compact('daten'))

zillion42 commented 1 year ago

compact('daten')

That's how I do it for all other views, and of course it works. Thx again. 🤦 again

ismaelw commented 1 year ago

@zillion42 You are more then welcome!