Use Laravel-Dompdf and create pdf invoices.
This commit is contained in:
24
app/Http/Controllers/PdfController.php
Normal file
24
app/Http/Controllers/PdfController.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Option;
|
||||
use Barryvdh\DomPDF\Facade\Pdf;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class PdfController extends Controller
|
||||
{
|
||||
public function downloadInvoice(int $invoice_id): Response
|
||||
{
|
||||
$invoice = Invoice::find($invoice_id);
|
||||
$all_options = Option::all(['name', 'value']);
|
||||
$options = new \stdClass();
|
||||
foreach ($all_options as $option) {
|
||||
$key = $option->name;
|
||||
$options->$key = $option->value;
|
||||
}
|
||||
|
||||
return Pdf::loadView('pdfs.invoice', ['invoice' => $invoice->load(['address', 'delivery']), 'options' => $options])->stream();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user