Viernes

@Snapey i tried a lot of method but didn't work just this method worked for me can you give us the right method that would work

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

@viernes You understand the problem right? If you mention localhost in your src= tags then when you want to move it to your hosting, then all your references will be broken.

The correct function, as mentioned here is asset, eg asset('img/photo.jpg');

For this to work, you MUST have the public folder as the Document Root , ie, the root of your website / should be the index.php in your public folder.

jlrdw
jlrdw
3 weeks ago (251,320 XP)

I have never seen so many folks having trouble simply displaying an image.

Shared or dev folder structure:

https://imgur.com/Oo6k4Fp

DO may be different, but they actually have tutorials.

And go to the docs and find the asset helper.

<img src="<?php echo asset('assets/upload/imgdogs') . '/' . $row->dogpic; ?>" alt="" class="image">

I am not making it up, It is really that easy.

I used php echo, just convert to blade, as don't use blade.

Folks new to laravel, I promise if you would goto them docs and work Taylor's examples you would really learn this stuff.

And Jeffrey has free videos on many of the basics.

Viernes

@Snapey thanks i got it now. @jlrdw yeah may something Simple make a big impact for the new folks to laravel.

@davy_yg if you want it to be a dynamic use this with your own application

<img width="70" src="{{asset('images/'.$post->photo['path'])}}">
Inquisitive

You could use

{{url('/images/icon-check.png')}}

Even if you are accessing through localhost/project/public.

And if this is already solved, please mark it as solved.

Cronix
Cronix
3 weeks ago (783,370 XP)

The main thing is to have APP_URL set correctly in the .env file, and then use the asset helpers. APP_URL should bring you to the homepage of the app. So you if you need to access http://localhost/some/project/public to get to your homepage, that's what it should be set for. Then when you change hosts, all you need to do is change APP_URL to the new domain name and everything will still work. The best thing though is to set up a actual host on your dev server so you can just access it with http://projectname.test so you don't have to have the path of the site in the url.

The asset helpers use the APP_URL to help generate the full url.

jlrdw
jlrdw
3 weeks ago (251,320 XP)

You don't even have to use helper.

something Simple make a big impact for the new folks to laravel.

I agree but it still just an image SRC you could do it the same way you did in PHP prior to going to laravel. Even your basic HTML studies it's the same way. Taylor just threw in a helper is all, like yii and cakephp they have helpers.

Echo out what the helper does and you will see it's as though you typed it all out anyway.

In fact I went over a year before I stumbled across the helper, and was just doing it the normal way anyway. I definitely like some of the helpers Taylor put in.

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