Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Public image not showing Laravel 10 #1058

Open
matiassemelman opened this issue Jun 28, 2024 · 7 comments
Open

Public image not showing Laravel 10 #1058

matiassemelman opened this issue Jun 28, 2024 · 7 comments

Comments

@matiassemelman
Copy link

Hello there, I'm using Laravel 10.10, and package 2.1.

I have my logo on public/ folder, just there.
This is my function:
private function generateLogo()
{
return "<img src='{{public_path('./pathful-logo') }}' alt='pathful-logo' class='logo' />";
}

I used public_path(), base_path(), with and without {{ }}.

@GanonthaBr
Copy link

I am facing the same issue but with Laravel 11.x.x

@parallels999
Copy link

parallels999 commented Jul 9, 2024

did you try with asset()?

Also #1059 (comment)

@chanakaDe
Copy link

I'm facing the same issue in Laravel 11.x :-(

@sven-ahrens
Copy link

sven-ahrens commented Aug 5, 2024

Can confirm.

Tried it with helper methods like asset, tried absolute and relative paths, also tried SetOptions (Which, even if it would be expected behaviour, would be weird)

I just get this screen.

Bildschirmfoto 2024-08-05 um 11 25 24

Nasty Hack

What actually works and it's a workaround for me: Just encode your file in base64 ;)

'logo' => 'data:image/png;base64,' . base64_encode(file_get_contents(public_path('images/logo.png'))),

@sven-ahrens
Copy link

sven-ahrens commented Aug 5, 2024

Hm actually, got to apologize: Made it work with public_path.

@matiassemelman did you try it without the leading ./ in your scenario?

In my example:

src="{{ public_path('/images/logo.png') }}"

it does work

but in your scenario the output would be something like: "/application/public/./images/logo.png"

the dot actually ruins the path

@GanonthaBr
Copy link

Laravel 11.x

I was able to fix the problem with:

$imagePath = public_path('images/logo.png');
$image = "data:image/png;base64," . base64_encode(file_get_contents($imagePath));

inside my controller and passed the $image vairiable down to the view which allowed me to used it inside my <img> tag easily like this: <img src="{{$image}}"/>

Check my Controller here:
https://github.com/GANONTHA/Belle-House-Automated-Invoice/blob/master/app/Http/Controllers/PDFExportController.php

@Sahrija
Copy link

Sahrija commented Aug 20, 2024

Laravel 11.x

I was able to fix the problem with:

$imagePath = public_path('images/logo.png'); $image = "data:image/png;base64," . base64_encode(file_get_contents($imagePath));

inside my controller and passed the $image vairiable down to the view which allowed me to used it inside my <img> tag easily like this: <img src="{{$image}}"/>

Check my Controller here: https://github.com/GANONTHA/Belle-House-Automated-Invoice/blob/master/app/Http/Controllers/PDFExportController.php

bro, you saved my live, i was figuring this problem for days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants