I have installed Laravel and began trying to write an app. I made some directories for my assets in the same directory as /app. But when I try to visit an image in my localhost for example: http://localhost/assets/images/image.png
I've also tried it on: http://localhost/app/assets/images/image.png
I ran into the problem when I was trying to set a background image in a view, and it kept going to 404.
This is what my app looks like under app/
->app
->assets
->commands
->config
->controllers
->database
->lang
->models
->start
->storage
->tests
->views
app.txt
routes.php
filters.php
But I get errors about requests. I have double checked that the url is correct.
Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
You have to do two steps:
url({{ URL::asset('images/slides/2.jpg') }})
where images/slides/2.jpg
is path of your content.Similarly you can call js, css etc.
Besides put all your assets in the public folder, you can use the HTML::image()
Method, and only needs an argument which is the path to the image, relative on the public folder, as well:
{{ HTML::image('imgs/picture.jpg') }}
Which generates the follow HTML code:
<img src="http://localhost:8000/imgs/picture.jpg">
The link to other elements of HTML::image()
Method: http://laravel-recipes.com/recipes/185/generating-an-html-image-element
You have to put all your assets in app/public
folder, and to access them from your views you can use asset()
helper method.
Ex. you can retrieve assets/images/image.png
in your view as following:
<img src="{{asset('assets/images/image.png')}}">
Source: Stackoverflow.com