Skip to content

Instantly share code, notes, and snippets.

@johanvanhelden
Last active March 17, 2022 09:01
Show Gist options
  • Save johanvanhelden/312b4e9586989174a42938ebe533b7bf to your computer and use it in GitHub Desktop.
Save johanvanhelden/312b4e9586989174a42938ebe533b7bf to your computer and use it in GitHub Desktop.
Fix for barryvdh/laravel-dompdf v1.0 with public folders other than "public"

In release 1.0 of the barryvdh/laravel-dompdf, the public path has been hardcoded. If you are using a public folder other than public, there will be an exception.

Add the code from this gist to your AppServiceProvider so everything will work until a fix has been released by barryvdh.

<?php
declare(strict_types=1);
namespace App\Providers;
// snip
use Dompdf\Dompdf;
// snip
class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
// snip
}
public function register(): void
{
// override the DOMPDF binding until the following PR has been merged:
// https://github.com/barryvdh/laravel-dompdf/issues/868
$this->app->bind('dompdf', function ($app) {
$options = $app->make('dompdf.options');
$dompdf = new Dompdf($options);
$path = realpath(public_path());
if ($path === false) {
throw new \RuntimeException('Cannot resolve public path');
}
$dompdf->setBasePath($path);
return $dompdf;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment