Support the ongoing development of Laravel.io →
Configuration
Last updated 2 years ago.
0

By default, all of your front-end assets (images, styles, JavaScript) should be stored in /public folder. Laravel itself doesn't go with any further convention, so it's up to you how you organize those files within /public folder. I like having /public/images, /public/css and /public/js folders.

It's important for you to understand what is public scope of your application. Some frameworks, including Laravel, separate files to public scope and private scope. Other frameworks just block access to core files, but Laravel does more. It not only blocks access, but also keeps it one level higher, outside of your document root. Your domain is (should be) pointed to /public folder and this is what is being used by domain. Other files can be required by PHP scripts, but there's no way to access them directly from your domain. Your assets are then requested by URLs, so if your domain is mysite.com and it's pointing to /public folder, you might have some images in let's say /public/images folder. For example, there's /public/images/cat.png image, so you could display it by:

<img src="http://mysite.com/images/cat.png";>

But Laravel helps you and provides helpers to be more flexible, read on: http://laravel.com/docs/4.2/helpers#urls

<img src="{{{ asset('images/cat.png') }}}">

This way you don't need to explicitly write down your site's domain. It shouldn't be hardcoded anywhere.

There are also more advanced techniques of managing assets, like assets pipeline, but for now just assume that /public folder is where you should keep your images, styles and JavaScripts.

I hope it helps a little :)

0

Thanks a lot for your reply :)

Yeah, this helped me a bit :) It was pretty much as I expected, and its just the actual syntax Im having trouble with I guess. Tomorrow I will watch through a bunch of video tutorials about Laravel, and I suppose a lot will fall in place then. But I would love to at least get the idea of how my issue is fixed before, because it will actually explain a lot about how all this works together.

So I have routed and configurated controller to open "hello.php" inside views (or well, it was like this by default". But when I tried to add the laravel img code inside of it, it did not find any images :( Im using PhpStorm, and it said that the Directory was not found. When I clicked "Create directory", a directory called {{{ asset(' was created inside the views folder :o

However, using the hard code seems to work.. So, yayy - I guess :p But the laravel helper way is really easier as Im just on localhost now. Should a copy paste into a blank php file work?

0

Sign in to participate in this thread!

Eventy

Your banner here too?

mariusf91 mariusf91 Joined 27 Jan 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.