refering to public path

Published 3 weeks ago by davy_yg

Hello,

I forget how to refer to public path ?

<img src="images/icon-check.png">

The images is in public/images/icon-check.png

tykus
tykus
3 weeks ago (690,060 XP)

Add a leading forward slash so that the path is relative to public rather than your current URL:

<img src="/images/icon-check.png">
nikos
nikos
3 weeks ago (6,420 XP)

You can do it like this <img src="{{ assets('images/icon-check.png') }}">

Viernes

You Can Do it like

<img src="http://localhost/app/public/images/{{$post->photo_path}} >
Snapey
Snapey
3 weeks ago (1,036,605 XP)

er.. don't do it as @Viernes suggests or you will have to visit very image and change the URL before you can put it into production

Robstar

If you ever need the fully qualified path you can use https://laravel.com/docs/5.7/helpers#method-public-path

tykus
tykus
3 weeks ago (690,060 XP)

Why would you ever need a fully qualified path in an <img> tag?

Snapey
Snapey
3 weeks ago (1,036,605 XP)

omg

davy_yg

Is this public?

<img src="{{ assets('images/icon-check.png') }}">

I also try:

 <img src="/images/icon-check.png">  

It does not detect the image.

lostdreamer_nl

@davy_yg

Make sure you are using your app with a domain name pointing to the public folder.

so do not use your laravel app in development as 'http://localhost/public' but as 'http://my-awesome-app.test'

davy_yg

my path is http://localhost/ids/public

It is not on the domain yet. I have to tested it on the localhost.

davy_yg

My first post suddenly works.

<td><?php if($item->status == "active") { echo '<img src="images/icon-check.png">'; } else { echo '<img src="images/icon-check.png">'; } ?></td>
nikos
nikos
3 weeks ago (6,420 XP)

If you're using laravel, why use php in .blade files. Second thing is that both your then and else code blocks are exactly the same. If you need to show different image according to the item status you could do something like this

<td> <img src="@if ($item->status == "active") {{ asset('images/icon-check.png') }} @else {{ asset('images/second-image.png') }}  @endif"></td>
nikos
nikos
3 weeks ago (6,420 XP)

Oh I'm sorry, in my first comment I made a typo. The functions name isn't assets() its asset(). :)

Snapey
Snapey
3 weeks ago (1,036,605 XP)

and fix your hosting. public should never appear in your URLs

jlrdw
jlrdw
3 weeks ago (251,320 XP)

my path is http://localhost/ids/public

Jumping Jupiter, how many times has this been discussed and answered.

Use VH. Or if WAMP, set up like a host, this guide works for shared host and development (wamp).

http://novate.co.uk/deploy-laravel-5-on-shared-hosting-from-heart-internet/

and for reference

Using git and droplet: https://devmarketer.io/learn/deploy-laravel-5-app-lemp-stack-ubuntu-nginx/

https://laracasts.com/discuss/channels/tips/hosting-on-shared-server-best-practice

I wish I had a dollar for every time a proper laravel install setup was discussed.

Please sign in or create an account to participate in this conversation.