Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

successdav's avatar

Laravel Dompdf not displaying image

Hi! I new with working with Laravel Dompdf, On the PDF i have been able to generate, the image is not displaying, instead it displays the path to the image.

here is the code

//My Controller 

public function index(User $user)
    {
        $subscriptions = $user->subscriptions()->with('subscriber');

        $pdf = PDF::loadView('pdfs.studentcard', compact('user','subscriptions'))->setPaper('a5', 'landscape');  
        return $pdf->stream('medium.pdf');
    }

My PDF Blade file

<table style="width: 100%">
    <tr>
        <td>
            <div>{{$user->avatar_path}}</div>
        </td>
        <td>Course Information</td>
    </tr>
</table>

and my method to retrieve users avatar

    public function getAvatarPathAttribute($avatar)
    {
        if ($avatar) {
            return asset('storage/' . $avatar);
        }else {
            return asset('storage/avatars/default.jpg');
        }
    }

Here is the output on the pdf

http://success.test/storage/avatars/default.jpg

Thanks for your help

0 likes
1 reply
successdav's avatar
successdav
OP
Best Answer
Level 4

What a shame I couldn't take some time to read over my code, I am using a div instead of an img tag, sorry to bother you all. thanks

Please or to participate in this conversation.