Home > Net >  Laravel PDF issue with getting image from Storage location
Laravel PDF issue with getting image from Storage location

Time:10-18

On using the following setups,

"php": "^7.3|^8.0",
"barryvdh/laravel-dompdf": "^0.9.0",
"fideloper/proxy": "^4.4",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"laravel/framework": "^8.81",

the PDF works well in the local host and the Plesk server. But unfortunately, the PDF is not generating in the greendc Server.

The Laravel Controller code is:

$pdf = PDF::loadView('pdf/topicDetail',$topic); 
$pdf->setPaper('A4', 'landscape');
$fileName = 'export-'. date('m-d-Y-His').'.pdf';
Storage::put('public/uploads/docs/downloads/'.$fileName, $pdf->output());
$link =  Storage::disk('docs')->url('downloads/'.$fileName);
return $this->successResponse($link);

The Blade code snapshot is:

<td style="text-align: center; padding: 10px;">
<img src="<?php echo asset("storage//uploads/download/data/img/Pol_filled.png")?>" alt="img">
<img src="<?php echo asset("storage//uploads/download/data/img/Pol.png")?>" alt="img">
</td>

We getting a strict-origin-when-cross-origin error in the greendc Server, the Server is unable to access the image from the Storage folder.

So my query is:

  1. Is this Server related error?
  2. greendc Server never access the Storage (Symbolic links)?
  3. using is not a proper method ?

we already given Storage link, other setup and all

CodePudding user response:

We can't use "echo assets" in the blade file.

So use

<td style="text-align: center; padding: 10px;">
<img src="{{ public_path('uploads/download/data/img/Pol_filled.png') }}" alt="img">
<img src="{{ public_path('uploads/download/data/img/Pol.png') }}" alt="img">
</td>

this will works well for all types of images

  • Related