Sabtu, 16 Oktober 2021

Laravel Dompdf

Buka terminal lalu ketikan

composer require barryvdh/laravel-dompdf


Buka file config/app.php

'providers' => [

Barryvdh\DomPDF\ServiceProvider::class,

],  

'aliases' => [

'PDF' => Barryvdh\DomPDF\Facade::class,

]

Lalu buat routernya

Route::get('/report/booth/pdf', [ReportController::class, 'booth_pdf']);

Lalu buat methode di controller

public function booth_pdf()

    {

        $data = $this->getData("booth")->data;

        $pdf = PDF::loadview('report.booth.pdf', ['list'=> $data]);

    return $pdf->download('report-booth.pdf');

    }

Lalu buat file viewnya

<!DOCTYPE html>

<html>

<head>

<title>Report Reward</title>

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

</head>

<body>

  <div class="">

<center>

<h4>Report Reward</h4>

</center>

<br/>

<table class='table table-bordered'>

<thead>

<tr>

<th>#</th>

                    <th>Name</th>

<th>Price</th>

<th>Purchased</th>

<th>Requested</th>

<th>Stock</th>

</tr>

</thead>

<tbody>

@php $number = 1; @endphp

@foreach ($list as $item)

<tr>

<td>{{$number}}</td>

<td>{{$item->name}}</td>

<td>{{$item->price}}</td>

<td>{{$item->purchased}}</td>

<td>{{$item->requested}}</td>

<td>{{$item->stock}}</td>

</tr>

@php $number++; @endphp

@endforeach

</tbody>

</table>

  </div>

 </body>

</html>

Load disqus comments

0 komentar