D
D
Dmitry28PRO2020-11-24 19:07:50
Laravel
Dmitry28PRO, 2020-11-24 19:07:50

How to correctly display the data of the user on which the button was pressed?

Good time of the day, guys, help me, I have an Invoices tab and in the database I created a connection between the invoices and the User, now when the person who clicked on the "button" is written to the Invoice table and the user's data is also recorded in the table with the help of links. Also, next to each user there are buttons "show invoice or download invoice".
After clicking on the button, an html invoice is generated in a separate page. and there I iterate over the foreatch array with data that is received from the database. and here is such a problem, if I have 2 invoices with different users, different data, then after clicking on the show invoice button, I get an invoice of 2 users, and not a specific invoice of the user who clicked on the button. How can I assign the data of one invoice for one user, so that everything is correct.
What if there was an invoice for user 1, then an invoice was formed with the data of user 1. etc.
here is the controller code:

public function invoiceView()
    {
        $this->user = Auth::User();
        $pdf = PDF::loadView('pdf.invoice', ['data' => user::all()]);
        return $pdf->stream('invoice.pdf');
    }

    public function invoiceDownload()
    {
        $this->user = Auth::User();
        $pdf = PDF::loadView('pdf.invoice', ['data' => user::all()]);
        return $pdf->download('invoice.pdf');
    }

Here is the invoice itself that is being generated
<center>Invoice</center>
@foreach ($data as $all)
  <br>
  ID USer:{{ $all['id'] }}<br>
  Name:{{ $all['name'] }}<br>
  Email:{{ $all['email'] }}<br>
  Phone:{{ $all['phone'] }}<br>
@endforeach

Here is a link to the library https://github.com/barryvdh/laravel-dompdf
if you need to drop something else, write. Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2020-11-24
@Nc_Soft

$this->user = Auth::User();
$pdf = PDF::loadView('pdf.invoice', ['data' => user::where('id', $this->user->id)->get()]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question