PHP code example of ambengers / eloquent-pdf
1. Go to this page and download the library: Download ambengers/eloquent-pdf library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ambengers / eloquent-pdf example snippets bash
php artisan vendor:publish --tag=eloquent-pdf-config
bash
$ php artisan make:eloquent-pdf PostPdf
php
namespace App\Pdf;
class PostPdf extends AbstractEloquentPdf
{
public function getData() : array
{
return [
'title' => $this->model->title,
'body' => $this->model->body,
];
}
public function getView() : string
{
return 'posts.pdf';
}
}
php
return app(PostPdf::class)
->model($post)
->download()
->handle();
php
return app(PostPdf::class)
->model($post)
->stream()
->handle();
php
return app(PostPdf::class)
->model($post)
->toMediaCollection('reports')
->handle();
php
namespace App\Pdf;
class PostPdf extends AbstractEloquentPdf
{
public function getOrientation(): string
{
return 'landscape';
}
public function getOptions(): array
{
return [
'footer-right' => 'Right footer text goes here!',
'footer-font-size' => 8,
'encoding' => 'UTF-8',
];
}
public function getFilename(): string
{
return 'new-file-name';
}
public function getExtension(): string
{
return 'odt';
}
}