Home > database >  How to manage image paths in DOMpdf in laravel 9
How to manage image paths in DOMpdf in laravel 9

Time:04-15

Since I updated to Laravel 9 the images in PDFs doesn't get found anymore. Is there any trick with the image source path in Laravel 9? Till now it worked with storage_path() in the pdf's blades.

I use the package Barryvdh\DomPDF

Do anybody know, how to solve that issue?

Thank you very much

CodePudding user response:

I found a way to solve this problem independently from the package: For the image source I defined a route outside of any middleware and defined a ResourceController which is returning the path. When you have several tables with image data, you have to define a route for each single table!

I could combine it easely with an authority check inside the Controller...

Blade:

<img src="{{ route('routename', [var1, var2]) }}">

web.php

Route::get('pathtoimages/{var1}/{var2}', 'ResourceController@getAuthorizedImage')->name('routename');

Controller:

public function getAuthorizedImage($var1, $var2, Request $request) 
{
    // any checks...
    $resource = ObjectImage::find($var2);

    return response()->file(Storage::path($resource->path));
    //image path saved in table column "path"
}

That's the way it works.

Stay healthy and peaceful

CruiseLee

  • Related