lazywaterpark
lazywaterpark
FFilament
Created by lazywaterpark on 10/17/2023 in #❓┊help
How can I render a PDF using a Livewire component that implements HasInfolists?
I've built an abstract component called App\Livewire\Pdf\Pdf . This component implements HasInfolists and HasForms.
abstract class Pdf extends Component implements HasForms, HasInfolists
{
use InteractsWithForms;
use InteractsWithInfolists;

#[Locked]
public mixed $record = [];

public function render(): View
{
return view(static::$view, $this->getRecord())
->layout(static::$layout, [
'title' => static::getTitle(),
]);
}

public function open(): Response
{
$pdf = \Barryvdh\DomPDF\Facade\Pdf::loadView(static::$view, ['record' => $this->getRecord()]);

return $pdf->stream();
}
}
abstract class Pdf extends Component implements HasForms, HasInfolists
{
use InteractsWithForms;
use InteractsWithInfolists;

#[Locked]
public mixed $record = [];

public function render(): View
{
return view(static::$view, $this->getRecord())
->layout(static::$layout, [
'title' => static::getTitle(),
]);
}

public function open(): Response
{
$pdf = \Barryvdh\DomPDF\Facade\Pdf::loadView(static::$view, ['record' => $this->getRecord()]);

return $pdf->stream();
}
}
This component is being used as an abstract class for App\Livewire\Pdf\MembershipAgreement. The class has its own blade file and headerInfolist method.
class MembershipAgreement extends Pdf
{
use HasMembershipInfolistSchema;
use HasMembershipPlanInfolistSchema;

protected static string $view = 'livewire.pdf.membership-agreement';

protected static string $layout = 'components.layouts.app';

public function headerInfolist(Infolist $infolist): Infolist
{
return $infolist
->record($this->getRecord())
->schema([
$this->getPlanTextEntry()
])
}
class MembershipAgreement extends Pdf
{
use HasMembershipInfolistSchema;
use HasMembershipPlanInfolistSchema;

protected static string $view = 'livewire.pdf.membership-agreement';

protected static string $layout = 'components.layouts.app';

public function headerInfolist(Infolist $infolist): Infolist
{
return $infolist
->record($this->getRecord())
->schema([
$this->getPlanTextEntry()
])
}
I have successfully created a rendered HTML file that routed to {base_url}/pdf/agreement/membership/{record}, using a typical render method. But when I tried to plug it in to \Barryvdh\DomPDF\Facade\Pdf, it throws an exception. In routes/web.php:
Route::name('membership.open')
->get('pdf/agreement/membership/{record}/open', [\App\Livewire\Pdf\MembershipAgreement::class, 'open']);
Route::name('membership.open')
->get('pdf/agreement/membership/{record}/open', [\App\Livewire\Pdf\MembershipAgreement::class, 'open']);
This is how the error looks: https://flareapp.io/share/67OwQOJ7 Thank you for reading to this point. Please let me know if this problem comes from me, Livewire, or barryvdh/laravel-dompdf.
6 replies